vitoco:

Nope. If you have functions that work on various objects, then create them that way. If you have class functions that don't require an object, just make them functions in the package. If you have functions that don't have anything to do with the class and/or objects, then put them somewhere else.

# foo.pm package foo; # class variables (not object instance variables) our %defaults = (bar=>0, foo=>7); # a couple typical object methods sub initialize { my $this = shift; $this->{instance_variable} = $defaults{bar}; } sub status { my $this = shift; return $this->{instance_variable}; } # a class method sub set_default_bar { $defaults{bar} = shift; } # etc...
use foo; my $frob = foo::new(); foo::set_default_bar(2); my $nitz = foo::new(); print "FROB=", $frob->status(), "\n"; print "NITZ=", $nitz->status(), "\n";

Untested, yadda, yadda, yadda.

...roboticus

In reply to Re: Modules exporting functions and objects at the same time. by roboticus
in thread Modules exporting functions and objects at the same time. by vitoco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.