package MyTest::Base;
use strict;
no autovivification;
sub new {
bless {}, shift;
}
sub chkAccessRight {
my $self = shift;
print "Base chkAccessRight @_$/";
my ( $usr, $service ) = @_ ;
return 1;
}
sub tryAccess {
my $self = shift;
print "Base tryAccess @_$/";
my ( $usr, $service ) = @_ ;
return $self -> chkAccessRight ( $usr => $service ) ;
}
1;
####
package MyTest::Lite;
no autovivification;
use parent 'MyTest::Base';
use strict;
sub new {
my $self = shift;
my $parent = $self -> SUPER::new ;
return bless { Parent => $parent, @_} , $self;
}
sub chkAccessRight {
my $self = shift;
print "Lite chkAccessRight @_$/";
if ( $self -> {Usr} ) {
return $self->{Parent}->SUPER::chkAccessRight ( $self->{Usr} , shift ) ;
}
else {
return $self->{Parent}->SUPER::chkAccessRight ( @_ ) ;
}
return 1;
}
sub tryAccess {
my $self = shift;
print "Lite tryAccess @_$/";
if ( $self -> {Usr} ) {
return $self->{Parent}->SUPER::tryAccess ( $self->{Usr} , shift ) ;
}
else {
return $self->{Parent}->SUPER::tryAccess ( @_) ;
}
}
1;
####
use MyTest::Lite;
use strict;
my $lite = new MyTest::Lite ( Usr => 'guest') ;
$lite -> chkAccessRight ( "app2" ) ;
print "======================$/";
$lite -> tryAccess ( "app1" );
####
Can't call method "SUPER::chkAccessRight" on an undefined value at MyTest/Lite.pm line 19.
Lite chkAccessRight app2
Base chkAccessRight guest app2
======================
Lite tryAccess app1
Base tryAccess guest app1
Lite chkAccessRight guest app1