| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #line 1 | 
| 2 |  |  |  |  |  |  | package UNIVERSAL::can; | 
| 3 | 16 |  |  | 16 |  | 80 |  | 
|  | 16 |  |  |  |  | 29 |  | 
|  | 16 |  |  |  |  | 463 |  | 
| 4 | 16 |  |  | 16 |  | 77 | use strict; | 
|  | 16 |  |  |  |  | 27 |  | 
|  | 16 |  |  |  |  | 402 |  | 
| 5 |  |  |  |  |  |  | use warnings; | 
| 6 | 16 |  |  | 16 |  | 76 |  | 
|  | 16 |  |  |  |  | 28 |  | 
|  | 16 |  |  |  |  | 816 |  | 
| 7 |  |  |  |  |  |  | use vars qw( $VERSION $recursing ); | 
| 8 |  |  |  |  |  |  | $VERSION = '1.16'; | 
| 9 | 16 |  |  | 16 |  | 78 |  | 
|  | 16 |  |  |  |  | 24 |  | 
|  | 16 |  |  |  |  | 2047 |  | 
| 10 | 16 |  |  | 16 |  | 97 | use Scalar::Util 'blessed'; | 
|  | 16 |  |  |  |  | 25 |  | 
|  | 16 |  |  |  |  | 1760 |  | 
| 11 |  |  |  |  |  |  | use warnings::register; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 16 |  |  | 16 |  | 81 | my $orig; | 
|  | 16 |  |  |  |  | 28 |  | 
|  | 16 |  |  |  |  | 793 |  | 
| 14 |  |  |  |  |  |  | use vars '$always_warn'; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | BEGIN | 
| 17 | 16 |  |  | 16 |  | 35 | { | 
| 18 |  |  |  |  |  |  | $orig = \&UNIVERSAL::can; | 
| 19 | 16 |  |  | 16 |  | 946 |  | 
|  | 16 |  |  |  |  | 32 |  | 
|  | 16 |  |  |  |  | 577 |  | 
| 20 | 16 |  |  |  |  | 790 | no warnings 'redefine'; | 
| 21 |  |  |  |  |  |  | *UNIVERSAL::can = \&can; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub import | 
| 25 | 16 |  |  | 16 |  | 29 | { | 
| 26 | 16 |  |  |  |  | 312 | my $class = shift; | 
| 27 |  |  |  |  |  |  | for my $import (@_) | 
| 28 | 0 | 0 |  |  |  | 0 | { | 
| 29 | 16 |  |  | 16 |  | 77 | $always_warn = 1 if $import eq '-always_warn'; | 
|  | 16 |  |  |  |  | 33 |  | 
|  | 16 |  |  |  |  | 4988 |  | 
| 30 | 0 | 0 |  |  |  | 0 | no strict 'refs'; | 
|  | 0 |  |  |  |  | 0 |  | 
| 31 |  |  |  |  |  |  | *{ caller() . '::can' } = \&can if $import eq 'can'; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub can | 
| 36 | 296923 |  |  | 296923 | 0 | 537177 | { | 
| 37 | 296923 |  |  |  |  | 328210 | my $caller = caller(); | 
| 38 |  |  |  |  |  |  | local $@; | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | # don't get into a loop here | 
| 41 |  |  |  |  |  |  | goto &$orig if $recursing | 
| 42 |  |  |  |  |  |  | || (   defined $caller | 
| 43 | 296923 | 100 | 33 |  |  | 1908339 | &&  defined $_[0] | 
|  | 152963 |  | 66 |  |  | 192481 |  | 
|  | 152963 |  | 66 |  |  | 465846 |  | 
| 44 |  |  |  |  |  |  | &&  eval { local $recursing = 1; $caller->isa($_[0]) } ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 152957 | 50 |  |  |  | 211348 | # call an overridden can() if it exists | 
|  | 152957 |  |  |  |  | 537136 |  | 
| 47 |  |  |  |  |  |  | my $can = eval { $_[0]->$orig('can') || 0 }; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 152957 | 50 |  |  |  | 299645 | # but only if it's a real class | 
| 50 |  |  |  |  |  |  | goto &$orig unless $can; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 152957 | 100 |  |  |  | 3523485 | # but not if it inherited this one | 
| 53 |  |  |  |  |  |  | goto &$orig if     $can == \&UNIVERSAL::can; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 225 |  |  |  |  | 368 | # redirect to an overridden can, making sure not to recurse and warning | 
| 56 | 225 |  |  |  |  | 318 | local $recursing = 1; | 
| 57 |  |  |  |  |  |  | my    $invocant  = shift; | 
| 58 | 225 |  |  |  |  | 397 |  | 
| 59 | 225 |  |  |  |  | 732 | _report_warning(); | 
| 60 |  |  |  |  |  |  | return $invocant->can(@_); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub _report_warning | 
| 64 | 225 | 50 | 33 | 225 |  | 17176 | { | 
| 65 |  |  |  |  |  |  | if ( $always_warn || warnings::enabled() ) | 
| 66 | 225 |  | 50 |  |  | 1147 | { | 
| 67 | 225 | 50 |  |  |  | 1065 | my $calling_sub = ( caller(2) )[3] || ''; | 
| 68 |  |  |  |  |  |  | warnings::warn("Called UNIVERSAL::can() as a function, not a method") | 
| 69 |  |  |  |  |  |  | if $calling_sub !~ /::can$/; | 
| 70 |  |  |  |  |  |  | } | 
| 71 | 225 |  |  |  |  | 381 |  | 
| 72 |  |  |  |  |  |  | return; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | 1; | 
| 76 |  |  |  |  |  |  | __END__ |