Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980235]
help
Chatterbox?
Discipulus redskins .. well native american..
[1nickt]: So if I was to offer any editorial advice it would be to (1) make it endure time passing (2) make it positive (3) make it about you and your beliefs
[1nickt]: (Disicpulus The new best choice is maybe "First People"
[karlgoethebier]: Discipulus: This is called "Volksverhetzung" in German which means
[karlgoethebier]: incitement of the people and it is prohibited by law
[1nickt]: The best sign I have sign in a protest march was carried by a kid of about 10 years "If you build a wall my generation will tear it down."
[1nickt]: ... sign I have seen ...
[1nickt]: Now that one made me hopeful! First time not angry in a long time when I saw that kid.
[Discipulus]: i propend for removing: why? because we are so few that we must find i minimal common divisor, this is certainly Perl not our (anyway private) thougths. And i say this still wondering because i love a lot freedom of expression. And i say this not for roho
[1nickt]: Discipulus that was the point of my story of taking the sticker off my truck. I know there are lots of people in the world who if I knw their private beliefs I might want to argue with them. And they with me. But life cannot all be arguments!

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-06-22 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.