line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Block::NamedVar::ForLike; |
2
|
6
|
|
|
6
|
|
14622
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
306
|
|
3
|
6
|
|
|
6
|
|
36
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
180
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
36
|
use Devel::Declare::Interface; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
420
|
|
6
|
6
|
|
|
6
|
|
30
|
use base 'Devel::Declare::Parser'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
7218
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Devel::Declare::Interface::register_parser( 'for_var' ); |
9
|
|
|
|
|
|
|
__PACKAGE__->add_accessor( $_ ) for qw/dec vars list var_count/; |
10
|
|
|
|
|
|
|
|
11
|
36
|
|
|
36
|
1
|
9522
|
sub is_contained{ 0 } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub rewrite { |
14
|
36
|
|
|
36
|
1
|
32268
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
36
|
50
|
|
|
|
60
|
if ( @{ $self->parts } > 3 ) { |
|
36
|
|
|
|
|
90
|
|
17
|
0
|
|
|
|
|
0
|
( undef, undef, my @bad ) = @{ $self->parts }; |
|
0
|
|
|
|
|
0
|
|
18
|
0
|
|
|
|
|
0
|
$self->bail( |
19
|
|
|
|
|
|
|
"Syntax error near: " . join( ' and ', |
20
|
0
|
|
|
|
|
0
|
map { $self->format_part($_)} @bad |
21
|
|
|
|
|
|
|
) |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
36
|
|
|
|
|
252
|
my ($first, $second, $third) = @{ $self->parts }; |
|
36
|
|
|
|
|
96
|
|
26
|
36
|
|
|
|
|
210
|
my ( $dec, $vars, $list ) = (""); |
27
|
36
|
100
|
|
|
|
42
|
if ( @{ $self->parts } > 2 ) { |
|
36
|
100
|
|
|
|
102
|
|
|
12
|
|
|
|
|
90
|
|
28
|
48
|
|
|
|
|
198
|
$self->bail( |
29
|
|
|
|
|
|
|
"Syntax error near: " . $self->format_part($first) |
30
|
24
|
50
|
|
|
|
126
|
) unless grep { $first->[0] eq $_ } qw/my our/; |
31
|
24
|
|
|
|
|
42
|
$dec = $first; |
32
|
24
|
|
|
|
|
30
|
$vars = $second; |
33
|
24
|
|
|
|
|
30
|
$list = $third; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ( @{ $self->parts } < 2 ) { |
36
|
6
|
|
|
|
|
60
|
$dec = ['local']; |
37
|
6
|
|
|
|
|
18
|
$vars = [' $a, $b ', '(']; |
38
|
6
|
|
|
|
|
12
|
$list = $first; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
6
|
|
|
|
|
48
|
$vars = $first; |
42
|
6
|
|
|
|
|
18
|
$list = $second; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
36
|
|
|
|
|
84
|
$self->vars( $self->format_vars( $vars )); |
46
|
36
|
|
|
|
|
252
|
$self->var_count( $self->count_vars ); |
47
|
36
|
|
|
|
|
240
|
$self->dec( $dec ); |
48
|
36
|
|
|
|
|
288
|
$self->list( $list ); |
49
|
|
|
|
|
|
|
|
50
|
36
|
|
|
|
|
276
|
$self->new_parts([]); |
51
|
36
|
|
|
|
|
210
|
1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format_vars { |
55
|
36
|
|
|
36
|
0
|
42
|
my $self = shift; |
56
|
36
|
|
|
|
|
48
|
my ( $vars ) = @_; |
57
|
36
|
100
|
|
|
|
132
|
return $vars if ref $vars; |
58
|
18
|
|
|
|
|
192
|
return [ $vars, '(' ]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub count_vars { |
62
|
36
|
|
|
36
|
0
|
48
|
my $self = shift; |
63
|
36
|
|
|
|
|
90
|
my @sigils = ($self->vars->[0] =~ m/\$/g); |
64
|
36
|
|
|
|
|
336
|
my @bad = $self->vars->[0] =~ m/[\@\*\%]/g; |
65
|
36
|
50
|
|
|
|
246
|
die( "nfor can only use a list of scalars, not " . join( ', ', @bad )) |
66
|
|
|
|
|
|
|
if @bad; |
67
|
36
|
|
|
|
|
144
|
return scalar @sigils; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
36
|
|
|
36
|
1
|
618
|
sub close_line {''}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub open_line { |
73
|
36
|
|
|
36
|
1
|
198
|
my $self = shift; |
74
|
36
|
100
|
|
|
|
84
|
my $dec = $self->dec ? $self->dec->[0] : ''; |
75
|
36
|
|
|
|
|
366
|
my $vars = $self->vars; |
76
|
36
|
|
|
|
|
204
|
return "; for my \$__ ( " |
77
|
|
|
|
|
|
|
. __PACKAGE__ |
78
|
|
|
|
|
|
|
. '::_nfor(' |
79
|
|
|
|
|
|
|
. $self->var_count |
80
|
|
|
|
|
|
|
. ", " |
81
|
|
|
|
|
|
|
. $self->list->[0] |
82
|
|
|
|
|
|
|
. ")) { " |
83
|
|
|
|
|
|
|
. "$dec ($vars->[0]) = \@\$__; "; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _nfor { |
87
|
6
|
50
|
|
6
|
|
619
|
return unless @_; |
88
|
6
|
|
|
|
|
66
|
my ( $num, @list ) = @_; |
89
|
6
|
|
|
|
|
13
|
my $i = 0; |
90
|
6
|
|
|
|
|
18
|
my @out; |
91
|
6
|
|
|
|
|
24
|
while ( $i < @list ) { |
92
|
11
|
|
|
|
|
59
|
push @out => [ @list[ $i .. ($i + $num - 1)] ]; |
93
|
11
|
|
|
|
|
28
|
$i += $num; |
94
|
|
|
|
|
|
|
} |
95
|
6
|
|
|
|
|
533
|
return @out; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |