line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Switch::Again; |
2
|
6
|
|
|
6
|
|
360909
|
use 5.006; use strict; use warnings; our $VERSION = '0.07'; |
|
6
|
|
|
6
|
|
72
|
|
|
6
|
|
|
6
|
|
27
|
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
121
|
|
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
282
|
|
3
|
6
|
|
|
6
|
|
2230
|
use Struct::Match qw/struct/; |
|
6
|
|
|
|
|
103498
|
|
|
6
|
|
|
|
|
40
|
|
4
|
6
|
|
|
6
|
|
785
|
use base qw/Import::Export/; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
872
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our %EX = ( |
7
|
|
|
|
|
|
|
'switch' => [qw/all/], |
8
|
|
|
|
|
|
|
'sr' => [qw/all/] |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
|
|
|
|
|
|
@STRUCT{qw/Regexp CODE/} = ( |
13
|
9
|
|
|
|
|
41
|
sub { $_[1] =~ $_[0]; }, |
14
|
6
|
|
|
|
|
14
|
sub { my $v = eval { $_[0]->($_[1]) }; } |
|
6
|
|
|
|
|
13
|
|
15
|
6
|
|
|
6
|
|
1869
|
); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub switch { |
19
|
15
|
|
|
15
|
1
|
3599
|
my ($value, $default, @cases); |
20
|
15
|
100
|
|
|
|
51
|
$value = shift if (scalar @_ % 2); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$_[0] eq 'default' |
23
|
9
|
|
|
|
|
53
|
? do { shift; $default = shift } |
|
9
|
|
|
|
|
21
|
|
24
|
15
|
100
|
|
|
|
55
|
: do { push @cases, { ref => $STRUCT{REF}($_[0]), case => shift, cb => shift } } |
|
26
|
|
|
|
|
159
|
|
25
|
|
|
|
|
|
|
while (@_); # I could map to a hash but... |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $evil = sub { |
28
|
35
|
|
|
35
|
|
9384
|
my ($val, @result) = ($_[0]); |
29
|
|
|
|
|
|
|
eval { |
30
|
69
|
|
|
|
|
160
|
@result = $STRUCT{$_->{ref}}($_->{case}, $val); |
31
|
69
|
100
|
100
|
|
|
1722
|
@result = () if @result && $result[0] eq ''; |
32
|
69
|
|
|
|
|
139
|
@result; |
33
|
|
|
|
|
|
|
} and do { |
34
|
|
|
|
|
|
|
@result = ref $_->{cb} eq 'CODE' ? $_->{cb}->($val, @result) : $_->{cb} |
35
|
35
|
100
|
100
|
|
|
68
|
} and last for @cases; |
|
25
|
|
100
|
|
|
92
|
|
36
|
34
|
100
|
100
|
|
|
449
|
@result ? wantarray ? @result : shift @result : $default && $default->($val); |
|
|
100
|
|
|
|
|
|
37
|
15
|
|
|
|
|
81
|
}; |
38
|
|
|
|
|
|
|
|
39
|
15
|
100
|
|
|
|
58
|
$value ? $evil->($value) : $evil; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub sr { |
43
|
1
|
|
|
1
|
1
|
432
|
my ($search, $replace) = @_; |
44
|
1
|
|
|
1
|
|
11
|
return sub {my $v589 = shift; $v589 =~ s/$search/$replace/g; $v589;}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
4
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__; |