in reply to accessing subs/methods from the module
You can access anything you want by fully qualifying it with a package name; e.g. in Blah:
The danger here is that Foobar is acting like an instance method and wants an object reference as its first argument. You don't have one just calling it as shown above. To do that you need to create a Foobar object first, in which case access is as you'd expect:use Foobar; sub doSomething { Foobar::some_method(); }
my $f = Foobar->new(); $f->some_method();
Make sure you understand the difference between class and instance methods before digging in too far here. Perl also lets you write methods that do either if you want, as much as that pisses off some OO purists:
I say "hopefully" in the comment because you could trip yourself up by doing this:sub class_or_instance { my $invocant = shift; if (ref($invocant)) { # got an instance (i.e., a "self" reference) } else { # got a class name (hopefully anyway ... 8-) } } ... Foobar->class_or_instance() # passes class name "Foobar" in as @_[0] my $f = Foobar->new(); $f->class_or_instance(); # passes object $f in as @_[0]
Tighter error checking is left as an exercise for the reader. 8-)Foobar::class_or_instance('blech');
|
|---|