in reply to Re: Exporter/@ISA confusion
in thread Exporter/@ISA confusion
The Perl module simply has do look like the following:use strict; use warnings; use MyClass::A (); my $s = MyClass::A->new(); $s->serve();
In the past Exporter was used to make it more convenient to load subroutines for use without having to deal with namespaces, but as it turns out using fully qualified namespaces is a really great thing to do. If you create a simple object via module using "traditional" Perl OOP, then you only have to type out the namespace once during construction. After that, the fact that the instance variable is blessed with the namespace means that you don't have to keep telling Perl what to use.use strict; use warnings package MyClass::A; sub new { my $pkg = shift; my $self = {}; return bless $self, $pkg; } sub serve { my $self = shift; # .. do whatevs } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Exporter/@ISA confusion
by qhen (Acolyte) on Jun 10, 2014 at 08:55 UTC | |
by Corion (Patriarch) on Jun 10, 2014 at 09:17 UTC | |
by qhen (Acolyte) on Jun 11, 2014 at 11:41 UTC | |
by perlfan (Parson) on Jun 10, 2014 at 12:50 UTC |