Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Perl does not recognize object method

by ig (Vicar)
on Jul 06, 2012 at 09:57 UTC ( #980235=note: print w/ replies, xml ) Need Help??


in reply to Perl does not recognize object method

I don't see an obvious cause of the error you get in the code you posted, but what you posted is obviously not what you ran when you got the error, so that doesn't mean much.

Maybe the following code does something like what you want and you can incorporate how it does it into your code.

use strict; use warnings; use Data::Dumper; package ClassA; sub new { my $class = shift; my ($client) = @_; my $self = bless {}, $class; if($client eq 'Veda') { $self = ClassB->new(); } return $self; } sub login { print "ClassA login\n"; } package ClassB; sub new { my $class = shift; bless {}, $class; } sub login { print "ClassB login\n"; } package main; print "obj1\n"; my $obj1 = ClassA->new('Veda'); print Dumper($obj1); $obj1->login(); print "obj2\n"; my $obj2 = ClassA->new('Other'); print Dumper($obj2); $obj2->login();

Output is

obj1 $VAR1 = bless( {}, 'ClassB' ); ClassB login obj2 $VAR1 = bless( {}, 'ClassA' ); ClassA login


Comment on Re: Perl does not recognize object method
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2014-07-25 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls