Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Module ( method ) alias ?

by Anonymous Monk
on Oct 04, 2012 at 05:36 UTC ( #997183=note: print w/replies, xml ) Need Help??

in reply to Module ( method ) alias ?

call'em inheritance
package AudioRecord; use parent qw' ManVideo '; sub new { my $class = shift; ... my $obj = $class->SUPER::new( @_ ); ... return $obj; }

my $rec = AudioRecord->new( ... );

perlootut, Modern Perl

Replies are listed 'Best First'.
Re^2: Module ( method ) alias ?
by exilepanda (Pilgrim) on Oct 04, 2012 at 07:04 UTC
    Thanks for answering. However seems work out a bit weird..

    package ModB; use parent qw'ModA'; sub new { my $c = shift; return $c->SUPER::new ( @_ ) ; } 1;

    package ModA; sub new { return bless {}, shift } sub p { print @_ } 1;

    use ModB; my $b = ModB->new(); $b -> p ( "World!" ) ;

    It prints ModB=HASH(0x182a5e4)World!. Don't know what am I missed. Also, could you explain a little what is SUPER:: referring to? Is it refer to where parent declared? And how can I inherit other methods with other method name?

    Thanks again!

      The first two lines do it all, all the others are only if you want to change something , like swap AudioType with VideoType ), Modern Perl and perlootut explain everything else, just use Ctrl+F to search
        Haha! yes, I got it now. And the problem of my sub p was that I forgot to shift the class ref, so it prints the ref address. Thanks again!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997183]
and the monastery is silent...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-01-19 00:47 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.