line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package namespace::sweep; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$namespace::sweep::VERSION = '0.006'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Sweep up imported subs in your classes |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
534327
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
326
|
|
9
|
8
|
|
|
8
|
|
47
|
use warnings; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
269
|
|
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
45
|
use Scalar::Util 'blessed', 'reftype'; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
1182
|
|
12
|
8
|
|
|
8
|
|
48
|
use List::Util 'first'; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
972
|
|
13
|
8
|
|
|
8
|
|
50
|
use Carp 'croak'; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
454
|
|
14
|
8
|
|
|
8
|
|
12569
|
use Data::Dumper; |
|
8
|
|
|
|
|
113786
|
|
|
8
|
|
|
|
|
732
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
7390
|
use Sub::Identify 0.04 'get_code_info'; |
|
8
|
|
|
|
|
11244
|
|
|
8
|
|
|
|
|
2410
|
|
17
|
8
|
|
|
8
|
|
7318
|
use B::Hooks::EndOfScope 0.09 'on_scope_end'; |
|
8
|
|
|
|
|
158163
|
|
|
8
|
|
|
|
|
65
|
|
18
|
8
|
|
|
8
|
|
8445
|
use Package::Stash 0.33; |
|
8
|
|
|
|
|
18632
|
|
|
8
|
|
|
|
|
2864
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$namespace::sweep::AUTHORITY = 'cpan:FRIEDO'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub import { |
23
|
11
|
|
|
11
|
|
480
|
my ( $class, %args ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
11
|
100
|
|
|
|
56
|
my $cleanee = exists $args{-cleanee} ? $args{-cleanee} : scalar caller; |
26
|
11
|
|
|
|
|
20
|
my @alsos; |
27
|
|
|
|
|
|
|
|
28
|
11
|
100
|
|
|
|
45
|
if ( exists $args{-also} ) { |
29
|
6
|
100
|
100
|
|
|
48
|
if ( ref $args{-also} && ( reftype $args{-also} eq reftype [ ] ) ) { |
30
|
2
|
|
|
|
|
13
|
@alsos = @{ $args{-also} }; |
|
2
|
|
|
|
|
7
|
|
31
|
|
|
|
|
|
|
} else { |
32
|
4
|
|
|
|
|
10
|
@alsos = ( $args{-also} ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
18
|
my @also_tests; |
37
|
11
|
|
|
|
|
22
|
foreach my $also( @alsos ) { |
38
|
0
|
|
|
0
|
|
0
|
my $test = !$also ? sub { 0 } |
39
|
11
|
|
|
11
|
|
49
|
: !ref( $also ) ? sub { $_[0] eq $also } |
40
|
0
|
|
|
8
|
|
0
|
: reftype $also eq reftype sub { } ? sub { local $_ = $_[0]; $also->() } |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
13
|
|
41
|
12
|
|
|
12
|
|
54
|
: reftype $also eq reftype qr// ? sub { $_[0] =~ $also } |
42
|
7
|
50
|
|
|
|
57
|
: croak sprintf q{Don't know what to do with [%s] for -also}, $also; |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
31
|
push @also_tests, $test; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $run_test = sub { |
48
|
64
|
100
|
|
64
|
|
291
|
return 1 if first { $_->( $_[0] ) } @also_tests; |
|
31
|
|
|
|
|
52
|
|
49
|
55
|
|
|
|
|
205
|
return; |
50
|
11
|
|
|
|
|
43
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
on_scope_end { |
53
|
8
|
|
|
8
|
|
161
|
no strict 'refs'; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
3736
|
|
54
|
11
|
|
|
11
|
|
1613
|
my $st = $cleanee . '::'; |
55
|
11
|
|
|
|
|
162
|
my $ps = Package::Stash->new( $cleanee ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $sweep = sub { |
58
|
|
|
|
|
|
|
# stolen from namespace::clean |
59
|
84
|
|
|
|
|
139
|
my @symbols = map { |
60
|
21
|
|
|
|
|
46
|
my $name = $_ . $_[0]; |
61
|
84
|
|
|
|
|
389
|
my $def = $ps->get_symbol( $name ); |
62
|
84
|
100
|
|
|
|
203
|
defined($def) ? [$name, $def] : () |
63
|
|
|
|
|
|
|
} '$', '@', '%', ''; |
64
|
|
|
|
|
|
|
|
65
|
21
|
|
|
|
|
112
|
$ps->remove_glob( $_[0] ); |
66
|
21
|
|
|
|
|
85
|
$ps->add_symbol( @$_ ) for @symbols; |
67
|
11
|
|
|
|
|
48
|
}; |
68
|
|
|
|
|
|
|
|
69
|
11
|
|
|
|
|
18
|
my %keep; |
70
|
11
|
|
33
|
|
|
163
|
my $class_of_cm = UNIVERSAL::can('Class::MOP', 'can') && 'Class::MOP'->can('class_of'); |
71
|
11
|
|
33
|
|
|
122
|
my $class_of_mu = UNIVERSAL::can('Mouse::Util', 'can') && 'Mouse::Util'->can('class_of'); |
72
|
11
|
50
|
33
|
|
|
14771
|
if ( $class_of_cm or $class_of_mu ) { |
73
|
|
|
|
|
|
|
# look for moose-ish composed methods |
74
|
0
|
|
|
|
|
0
|
my ($meta) = |
75
|
0
|
|
|
|
|
0
|
grep { !!$_ } |
76
|
0
|
|
|
|
|
0
|
map { $cleanee->$_ } |
77
|
0
|
|
|
|
|
0
|
grep { defined $_ } |
78
|
|
|
|
|
|
|
($class_of_cm, $class_of_mu); |
79
|
0
|
0
|
0
|
|
|
0
|
if ( blessed $meta && $meta->can( 'get_all_method_names' ) ) { |
80
|
0
|
|
|
|
|
0
|
%keep = map { $_ => 1 } $meta->get_all_method_names; |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
11
|
|
|
|
|
28
|
foreach my $sym( keys %{ $st } ) { |
|
11
|
|
|
|
|
63
|
|
85
|
64
|
100
|
50
|
|
|
116
|
$sweep->( $sym ) and next if $run_test->( $sym ); |
86
|
|
|
|
|
|
|
|
87
|
64
|
100
|
|
|
|
77
|
next unless exists &{ $st . $sym }; |
|
64
|
|
|
|
|
275
|
|
88
|
37
|
50
|
|
|
|
96
|
next if $keep{$sym}; |
89
|
|
|
|
|
|
|
|
90
|
37
|
|
|
|
|
42
|
my ( $pkg, $name ) = get_code_info \&{ $st . $sym }; |
|
37
|
|
|
|
|
157
|
|
91
|
37
|
100
|
|
|
|
146
|
next if $pkg eq $cleanee; # defined in the cleanee pkg |
92
|
13
|
100
|
66
|
|
|
63
|
next if $pkg eq 'overload' and $name eq 'nil'; # magic overload method |
93
|
|
|
|
|
|
|
|
94
|
12
|
|
|
|
|
41
|
$sweep->( $sym ); |
95
|
|
|
|
|
|
|
} |
96
|
11
|
|
|
|
|
168
|
}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |