in reply to Re^2: OO Perl: Nested classes question
in thread OO Perl: Nested classes question
Also I note that your "preferred way to call constructors" comment is just cargo culting unless you can give some concrete reasons why that is preferred.(of course you know this but) fear of imported subroutines is one reason ..
# Stuff.pm package Stuff; use base 'Exporter'; @EXPORT = qw(new); sub new { print "this is exported new!\n" }
# new.pl use Stuff; my $foo = Foo->new; # this works $foo->baz; my $bar = new Foo; # this doesn't $bar->baz; package Foo; sub new { my $class = shift; print "constructing a $class\n"; bless {}, $class; } sub baz { my $self = shift; print "hello from a ", ref $self, "\n"; }
% perl new.pl constructing foo hello from a Foo this is exported new! Can't call method "baz" without a package or object reference at new.pl line 9.
|
|---|