line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package match::simple::sugar; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
68946
|
use 5.006001; |
|
1
|
|
|
|
|
15
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
456
|
use Exporter::Tiny; |
|
1
|
|
|
|
|
3157
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
137
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
10
|
1
|
|
|
1
|
|
404
|
use match::simple qw( match ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
1
|
|
|
1
|
|
266
|
$match::simple::sugar::AUTHORITY = 'cpan:TOBYINK'; |
14
|
1
|
|
|
|
|
2
|
$match::simple::sugar::VERSION = '0.012'; |
15
|
1
|
|
|
|
|
2
|
my $strict = 0; |
16
|
1
|
|
100
|
|
|
10
|
$ENV{$_} && $strict++ for qw( |
17
|
|
|
|
|
|
|
EXTENDED_TESTING |
18
|
|
|
|
|
|
|
AUTHOR_TESTING |
19
|
|
|
|
|
|
|
RELEASE_TESTING |
20
|
|
|
|
|
|
|
PERL_STRICT |
21
|
|
|
|
|
|
|
); |
22
|
1
|
|
|
|
|
207
|
eval qq{ |
23
|
|
|
|
|
|
|
sub STRICT () { !! $strict } |
24
|
|
|
|
|
|
|
sub LAX () { ! $strict } |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @ISA = qw( Exporter::Tiny ); |
29
|
|
|
|
|
|
|
our @EXPORT = qw( when then numeric match ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $then_class = __PACKAGE__ . '::then'; |
32
|
|
|
|
|
|
|
my $numeric_class = __PACKAGE__ . '::numeric'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub when { |
35
|
5
|
|
|
5
|
1
|
132
|
my @things = @_; |
36
|
5
|
|
|
|
|
9
|
my $then = pop @things; |
37
|
5
|
100
|
66
|
|
|
40
|
if ( blessed $then and $then->isa( $then_class ) ) { |
38
|
4
|
100
|
|
|
|
35
|
if ( match $_, \@things ) { |
39
|
1
|
|
|
1
|
|
8
|
no warnings 'exiting'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
346
|
|
40
|
3
|
|
|
|
|
10
|
$then->(); |
41
|
3
|
|
|
|
|
1173
|
next; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
1
|
|
|
|
|
191
|
croak "when: expects then"; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
3
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _check_coderef { |
51
|
4
|
|
|
4
|
|
5
|
my $coderef = shift; |
52
|
4
|
|
|
|
|
20
|
require B; |
53
|
|
|
|
|
|
|
local *B::OP::__match_simple_sugar_callback = sub { |
54
|
32
|
|
|
32
|
|
136
|
my $name = $_[0]->name; |
55
|
32
|
50
|
|
|
|
116
|
croak "Block appears to contain a `$name` statement; not suitable for use with when/then" |
56
|
|
|
|
|
|
|
if match $name, [ qw/ wantarray return redo last next / ]; |
57
|
32
|
|
|
|
|
124
|
return; |
58
|
4
|
|
|
|
|
60
|
}; |
59
|
4
|
|
|
|
|
43
|
B::svref_2object( $coderef )->ROOT->B::walkoptree( '__match_simple_sugar_callback' ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub then (&) { |
63
|
4
|
|
|
4
|
1
|
23
|
my $coderef = shift; |
64
|
4
|
|
|
|
|
12
|
_check_coderef $coderef if STRICT; |
65
|
4
|
|
|
|
|
38
|
bless $coderef, $then_class; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub numeric ($) { |
69
|
1
|
|
|
1
|
1
|
91
|
my $n = shift; |
70
|
1
|
|
|
|
|
14
|
bless \$n, $numeric_class; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
my $check = sub { |
75
|
|
|
|
|
|
|
my ( $x, $y ) = map { |
76
|
1
|
100
|
66
|
1
|
|
5
|
( blessed $_ and $_->isa( $numeric_class ) ) |
|
2
|
|
|
|
|
18
|
|
77
|
|
|
|
|
|
|
? $$_ |
78
|
|
|
|
|
|
|
: $_; |
79
|
|
|
|
|
|
|
} @_[0, 1]; |
80
|
1
|
|
|
1
|
|
7
|
no warnings qw( numeric ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
81
|
1
|
50
|
33
|
|
|
61
|
defined $x and defined $y and !ref $x and !ref $y and $x == $y; |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
82
|
|
|
|
|
|
|
}; |
83
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
84
|
|
|
|
|
|
|
*{"$numeric_class\::MATCH"} = $check; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |