Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

Comment on Re: Module ( method ) alias ?
Download Code
Replies are listed 'Best First'.
Re^2: Module ( method ) alias ?
by exilepanda (Monk) 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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2015-10-09 00:28 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (232 votes), past polls