Hi there. I have two problems I'm experiencing with modules at the moment. The first - and smaller - problem is this. I have a file, Foo.pm, that contains something like this :
package Foo::Bar;
sub s1 {}
sub s2 {} ...
package Foo::Bar::Subclass1;
use base Foo::Bar;
...
package Foo::Bar::Subclass2;
use base Foo::Bar;
I'd like to call Foo::Bar::s1 from any of the subclasses.
But - I don't want to call them as class methods (ie $this->s1()). The motivation behind this is that s1, s2, etc aren't really directly related to Foo::Bar or its subclasses, but will be used by all of the subclasses as helper functions at some point.
I've tried using Foo::Bar::s1() from Foo::Bar::Subclass1 - but I get an error saying it could not be found. I *think* this is because the file is called Foo.pm, and not Foo/Bar.pm - but once again, I'm not sure. I've got it working right now by calling s1 from $this, but it seems to me that using $this->s1() for a function that never uses $this is inelegant. If there's an easy way to fix this, let me know.
Second Problem
Of course, the above problem stems from a more deeply-rooted problem - I don't know that much about the inner workings of modules and inheritance. I've tried to RTFM, but there's so much documentation out there, I only find snippets and bits in any place I look. Could anyone point me to a good resource about exactly how modules work? I've read what appeared to be the pertinent man pages (perltoot and perlmod, for instance), but they just provided enough to be usable, not the monk-like knowledge I just *know* is floating around there, somewhere.
Thanks!
James
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.