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.
...roboticusIn 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |