This prints:use strict; package A; sub new { my $pkg = shift; bless {}, $pkg; } sub first { print "A::first\n"; } sub second { print "A::second\n"; } sub check { my $this = shift; my $pkg = ref $this; print "\nResults of check:\n"; foreach my $subname (qw(first SUPER::first second SUPER::second)) +{ if (defined (my $sub = $this->can ($subname))) { print ("$pkg can $subname\n"); $this->$sub (); } else { print "$pkg cannot do $subname\n"; } } } package A_sub; @A_sub::ISA = qw(A); sub first { print "A_sub::first\n"; } sub check_sub { my $this = shift; my $pkg = ref $this; print "\nResults of check_sub:\n"; foreach my $subname (qw(first SUPER::first second SUPER::second)) +{ if (defined (my $sub = $this->can ($subname))) { print ("$pkg can $subname\n"); $this->$sub (); } else { print "$pkg cannot do $subname\n"; } } } package main; my $asub = new A_sub; $asub->check (); $asub->check_sub ();
Did everybody out there know this? I was quite surprised of the result.Results of check: A_sub can first A_sub::first A_sub cannot do SUPER::first A_sub can second A::second A_sub cannot do SUPER::second Results of check_sub: A_sub can first A_sub::first A_sub can SUPER::first A::first A_sub can second A::second A_sub can SUPER::second A::second
pike
In reply to Re: Re: can('SUPER::defaults')
by pike
in thread can('SUPER::defaults')
by kwoff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |