Given:
use warnings; use strict; package Frobnicate::Bar; sub new { my ($class) = @_; return bless {}, $class; } sub sayWhat { my ($self) = @_; if (ref $self) { print "I'm a ", ref $self, " method\n"; } else { print "I'm a ", __PACKAGE__, " function\n"; } } package Frobnicate::Foo; our @ISA = qw/Frobnicate/; sub new { my ($class) = @_; return Frobnicate::new ($class); } sub sayWhat { my ($self) = @_; if (ref $self) { print "I'm a ", ref $self, " method\n"; } else { print "I'm a ", __PACKAGE__, " function\n"; } } package Frobnicate; sub new { my ($class) = @_; return bless {}, $class; } sub sayWhat { my ($self) = @_; if (ref $self) { print "I'm a ", ref $self, " method\n"; } else { print "I'm a ", __PACKAGE__, " function\n"; } } 1;
consider:
use strict; use warnings; use noname1; Frobnicate::Bar->new ()->sayWhat (); Frobnicate::Foo->new ()->sayWhat (); Frobnicate->new ()->sayWhat (); Frobnicate::Bar::sayWhat (); Frobnicate::Foo::sayWhat (); Frobnicate::sayWhat ();
which prints:
I'm a Frobnicate::Bar method I'm a Frobnicate::Foo method I'm a Frobnicate method I'm a Frobnicate::Bar function I'm a Frobnicate::Foo function I'm a Frobnicate function
So, exactly what is hidden from the calling code exactly?
btw, I don't condone the use of the same sub as a method and a function. Used here to reduce code peripheral to the main thesis.
In reply to Re^2: How to create nested class in perl?
by GrandFather
in thread How to create nested class in perl?
by sarojt72
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |