in reply to Re: can('SUPER::defaults')
in thread can('SUPER::defaults')
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: can('SUPER::defaults')
by demerphq (Chancellor) on Oct 23, 2001 at 16:25 UTC | |
by chromatic (Archbishop) on Oct 23, 2001 at 23:03 UTC | |
by jackdied (Monk) on Oct 24, 2001 at 02:55 UTC |