John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
use 5.10.1; use strict; use warnings; { package Base; sub new { my $class= shift; return bless ({}, $class); } sub baz { my ($self,$x)= @_; say "Baz called: " . $self . " ($x)"; } } # end of class { package Derived; our @ISA = 'Base'; } # end of class say "I'm running."; my $d= Derived->new; $d->baz(1); Base->baz(2); Derived->baz(3);
However, trying some things with Moose:
use 5.10.1; use MooseX::Declare; class Base { sub baz { my ($self,$x)= @_; say "Baz called: " . $self . " ($x)"; } } #end of Base class Derived { method foo (Num $x) { say "Foo called: " . ref($self) . " ($x)"; } sub bar { my ($self,$x)= @_; say "Bar called: " . ref($self) . " ($x)"; } } #end of Derived say "I'm running."; my $d= Derived->new; $d->foo (1); #Derived->foo(2); #cannot call as static # this one is allowed. $d->bar (1); Derived->bar(2); $d->baz(1); Base->baz(2); Derived->baz(3); # does not find it!
Why not?
And how can it it not? If it uses the normal Perl mechanism to locate subs on instances, why doesn't it work on class names too?
Confused as ever,
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose and class methods
by chromatic (Archbishop) on Apr 30, 2011 at 17:54 UTC | |
by John M. Dlugosz (Monsignor) on May 01, 2011 at 10:28 UTC | |
|
Re: Moose and class methods
by stvn (Monsignor) on May 01, 2011 at 02:02 UTC | |
by John M. Dlugosz (Monsignor) on May 01, 2011 at 10:37 UTC | |
|
Re: Moose and class methods
by Anonymous Monk on Apr 30, 2011 at 12:51 UTC |