Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Module ( method ) alias ?

by exilepanda (Monk)
on Oct 04, 2012 at 07:04 UTC ( #997194=note: print w/ replies, xml ) Need Help??


in reply to Re: Module ( method ) alias ?
in thread Module ( method ) alias ?

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!


Comment on Re^2: Module ( method ) alias ?
Select or Download Code
Re^3: Module ( method ) alias ?
by Anonymous Monk on Oct 04, 2012 at 07:43 UTC
    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://997194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (19)
As of 2015-07-01 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (17 votes), past polls