| 1 | package Class::Util ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | $VERSION = 2.40 ; | |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.006_001 ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # This file uses the "Perlish" coding style | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # please read http://perl.4pro.net/perlish_coding_style.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ; use Carp | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | ; $Carp::Internal{+__PACKAGE__}++ | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ; sub import | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | { return unless @_ | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | ; require Exporter | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ; our @ISA = 'Exporter' | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ; our @EXPORT_OK = qw| load | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | gather | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | blessed | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | classes | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | | | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ; $_[0]->export_to_level(1, @_) | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ; sub load | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | { local $_ = $_[0] if defined $_[0] | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ; my $r = eval "require $_;" | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | ; if ($@) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | { (my $c = $_.'.pm') =~ s|\b::\b|/|g | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ; no strict 'refs' | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | ; croak $@ if $@ !~ /^Can't locate $c in \@INC/ | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | || not grep { /[^:][^:]\z/ } keys %{$_.'::'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ =~ /^Can't locate $c in \@INC/ and grep {/[^:][^:]\z/;} keys %{$_ . '::';}
MC/DC50%1/2
$@ =~ /^Can't locate $c in \@INC/ and grep {/[^:][^:]\z/;} keys %{$_ . '::';}
$@ =~ /^Can't locate $c in \@INC/
grep {/[^:][^:]\z/;} keys %{$_ . '::';}
Truth table66%2/3
A and B
A= $@ =~ /^Can't locate $c in \@INC/B= grep {/[^:][^:]\z/;} keys %{$_ . '::';}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ; $r | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ; sub gather (&$;$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | { my( $code, $symbol, $packages ) = @_ | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gather: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ; no strict 'refs' | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | ; unless ( ref $packages eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | { my $class = defined($packages) &&! ref($packages) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $packages and not ref $packages
blessed($packages) or caller
MC/DC100%2/2
defined $packages and not ref $packages
defined $packages
not ref $packages
MC/DC0%0/2
blessed($packages) or caller
blessed($packages)
caller
Truth table100%3/3
A and not(B)
A= defined $packagesB= not ref $packages
Truth table66%2/3
A or B
A= blessed($packages)B= caller
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ? $packages | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | : blessed($packages) || caller | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ; $packages = classes($class) | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ; my $t = substr $symbol, 0, 1, '' | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | ; my $type = $t eq '*' ? 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | : $t eq '&' ? 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | : $t eq '%' ? 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | : $t eq '@' ? 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | : $t eq '$' ? 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | : croak 'Identifier must start with [*&%@$], died' | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | ; map { $code->() } | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | map { *{$_.'::'.$symbol}{$type} } | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | grep { defined( $type eq 'SCALAR' | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | ? ${$_.'::'.$symbol} | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 16 | ▶ | : *{$_.'::'.$symbol}{$type} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | @$packages | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ; sub blessed | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 14 | ▶ | { local $_ = $_[0] if defined $_[0] | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blessed: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 14 | ▶ | ; defined && length && eval{ $_->isa( ref ) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $_ and length $_ and eval {
do {
$_->isa(ref $_)
}
}
defined $_ and length $_
MC/DC100%3/3
defined $_ and length $_ and eval {
do {
$_->isa(ref $_)
}
}
defined $_
length $_
eval {
do {
$_->isa(ref $_)
}
}
Truth table100%4/4
A and B and C
A= defined $_B= length $_C= eval {
do {
$_->isa(ref $_)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ? ref | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | : undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ; sub classes ($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | { my $class = shift | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
classes: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | ; return () unless $class | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | ; $class = blessed($class) || $class | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
blessed($class) || $class
MC/DC0%0/2
blessed($class) || $class
blessed($class)
$class
Truth table66%2/3
A || B
A= blessed($class)B= $class
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ; my @stack = ($class) | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | ; my %skip = ($class => 1) | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ; my (@classes, $c) | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | ; while ( @stack ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 23 | ▶ | { next unless defined($c = shift @stack) && length $c | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined($c = shift @stack) and length $c
MC/DC0%0/2
defined($c = shift @stack) and length $c
defined($c = shift @stack)
length $c
Truth table33%1/3
A and B
A= defined($c = shift @stack)B= length $c
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | ; unshift @classes, $c | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 4 | ▶ | ; no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 23 | ▶ | ; unshift @stack, map{ $skip{$_}++ ? () : $_ } @{$c.'::ISA'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | ▶ | ; wantarray ? @classes : \@classes | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ; 1 | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||