Hi, I'm trying to implement overriding methods. This is my code:
Base class:
use Net::Telnet(); use strict; use warnings; package L_Switch; sub new { my $class = shift; my ($location, $ip, $time, $client) = @_; my $self = {}; my $sucClass; if ((defined $client) and ($client eq "Veda")){ $subClass = "L_Switch::L_Veda"; } eval "use $subClass;"; eval "\$self = $subClass -> new();"; } sub login { my $self = shift; my $utility = L_Utility -> new(); $self -> {'telnetConn'} -> open($self -> {ip}); $self -> {'telnetConn'} -> login($self -> {'username'}, $self -> { +'password'}); if ($self -> {'time_out'} == 1) # checking +timed-out switches { $self -> {'full_info'} = $self -> {'full_info'} . "," . $self +-> {'location'}; $self -> {'full_info'} = $self -> {'full_info'} . "," . $self +-> {'fault'} . "," . $self -> {'time'} . ",,,,,"; return $self -> {'full_info'}; } return "0"; } 1;
Child class:
package L_Switch::L_Veda; require L_Switch; @ISA = qw(L_Switch); use strict; use warnings; use NET::SSH2; sub new { } # something in here sub login { my $self = shift; $self -> {'ssh'} -> connect($self -> {'ip'}); $self -> {'ssh'} -> auth_password($self -> {'username'}, $self -> +{'password'}); return 0; } 1;
Main script:
when I run the script, an error appeared: Can't locate object method "login" via package "L_Switch::L_Veda" at testSSH.pl line xx. Can anyone tell me what went wrong in my code. Thanks in advanceuse L_Switch; use strict; use warnings; my $utility = L_Utility -> new(); my $switch = L_Switch -> new("", '127.0.0.1', "", "Veda"); $switch -> login(); print $switch -> getFullInfo();
In reply to Perl does not recognize object method by lightbringer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |