Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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
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..

    ModB.pm

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

    ModA.pm

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

    main.pl

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-11-24 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (147 votes), past polls