line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Babble::Plugin::CoreSignatures; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
72367
|
use strictures 2; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
60
|
|
4
|
1
|
|
|
1
|
|
809
|
use Moo; |
|
1
|
|
|
|
|
7248
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
0
|
0
|
|
sub extend_grammar { } # PPR::X can already parse everything we need |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# .......bbbbbSSSSSSSa |
9
|
|
|
|
|
|
|
# sub foo :Bar ($baz) { |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# .......bSSSSSSSaaaaa |
12
|
|
|
|
|
|
|
# sub foo ($baz) :Bar { |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub transform_to_signatures { |
15
|
1
|
|
|
1
|
0
|
1923
|
my ($self, $top) = @_; |
16
|
|
|
|
|
|
|
my $tf = sub { |
17
|
4
|
|
|
4
|
|
91
|
my $s = (my $m = shift)->submatches; |
18
|
4
|
100
|
|
|
|
42
|
if ((my $after = $s->{after}->text) =~ /\S/) { |
19
|
2
|
|
|
|
|
21
|
$s->{after}->replace_text(''); |
20
|
2
|
|
|
|
|
19
|
$s->{before}->replace_text($s->{before}->text.$after); |
21
|
|
|
|
|
|
|
} |
22
|
1
|
|
|
|
|
6
|
}; |
23
|
1
|
|
|
|
|
6
|
$self->_transform_signatures($top, $tf); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub transform_to_oldsignatures { |
27
|
1
|
|
|
1
|
0
|
1087
|
my ($self, $top) = @_; |
28
|
|
|
|
|
|
|
my $tf = sub { |
29
|
4
|
|
|
4
|
|
81
|
my $s = (my $m = shift)->submatches; |
30
|
4
|
100
|
|
|
|
30
|
if ((my $before = $s->{before}->text) =~ /\S/) { |
31
|
2
|
|
|
|
|
13
|
$s->{before}->replace_text(''); |
32
|
2
|
|
|
|
|
17
|
$s->{after}->replace_text($before.$s->{after}->text); |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
8
|
}; |
35
|
1
|
|
|
|
|
5
|
$self->_transform_signatures($top, $tf); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub transform_to_plain { |
39
|
9
|
|
|
9
|
0
|
7370
|
my ($self, $top) = @_; |
40
|
9
|
|
|
|
|
40
|
$top->remove_use_argument(experimental => 'signatures'); |
41
|
9
|
|
|
|
|
98
|
$top->remove_use_argument('Mojo::Base' => '-signatures', 1); |
42
|
|
|
|
|
|
|
my $tf = sub { |
43
|
10
|
|
|
10
|
|
185
|
my $s = (my $m = shift)->submatches; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# shift attributes after first before we go hunting for :prototype |
46
|
10
|
100
|
|
|
|
77
|
if ((my $before = $s->{before}->text) =~ /\S/) { |
47
|
8
|
|
|
|
|
41
|
$s->{before}->replace_text(''); |
48
|
8
|
|
|
|
|
68
|
$s->{after}->replace_text($before.$s->{after}->text); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
10
|
|
|
|
|
70
|
my $proto = ''; |
52
|
|
|
|
|
|
|
{ |
53
|
10
|
|
|
|
|
21
|
my $try = $s->{after}; |
|
10
|
|
|
|
|
18
|
|
54
|
10
|
|
|
|
|
30
|
local $try->{top_rule} = 'Attributes'; |
55
|
10
|
|
|
|
|
195
|
my $grammar = $m->grammar->clone; |
56
|
10
|
|
|
|
|
1161
|
$grammar->add_rule(Attribute => |
57
|
|
|
|
|
|
|
'(?&PerlOWS) :? (?&PerlOWS) |
58
|
|
|
|
|
|
|
(?&PerlIdentifier) |
59
|
|
|
|
|
|
|
(?: (?= \( ) (?&PPR_X_quotelike_body) )?+' |
60
|
|
|
|
|
|
|
)->replace_rule(Attributes => |
61
|
|
|
|
|
|
|
'(?=(?&PerlOWS):)(?&PerlAttribute) |
62
|
|
|
|
|
|
|
(?&PerlAttribute)*' |
63
|
|
|
|
|
|
|
); |
64
|
10
|
|
|
|
|
32
|
local $try->{grammar} = $grammar; |
65
|
10
|
|
|
|
|
20
|
my $each; $each = sub { |
66
|
14
|
|
|
|
|
31
|
my ($attr) = @_; |
67
|
14
|
100
|
|
|
|
94
|
if ($attr->text =~ /prototype(\(.*?\))/) { |
68
|
7
|
|
|
|
|
19
|
$proto = $1; |
69
|
7
|
|
|
|
|
30
|
$attr->replace_text(''); |
70
|
|
|
|
|
|
|
$each = sub { |
71
|
2
|
|
|
|
|
6
|
my ($attr) = @_; |
72
|
2
|
50
|
|
|
|
24
|
$attr->transform_text(sub { s/^(\s*)/${1}:/ }) unless $attr->text =~ /^\s*:/; |
|
2
|
|
|
|
|
15
|
|
73
|
2
|
|
|
|
|
15
|
$each = sub {}; |
74
|
7
|
|
|
|
|
61
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
10
|
|
|
|
|
57
|
}; |
77
|
10
|
|
|
|
|
81
|
$try->each_match_of(Attribute => sub { $each->(@_) }); |
|
16
|
|
|
|
|
53
|
|
78
|
10
|
|
|
|
|
219
|
undef($each); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
138
|
s/\A\s*\(//, s/\)\s*\Z// for my $sig_orig = $s->{sig}->text; |
82
|
10
|
|
|
|
|
209
|
my $grammar_re = $m->grammar_regexp; |
83
|
10
|
|
|
|
|
390987
|
my @sig_parts = grep defined($_), |
84
|
|
|
|
|
|
|
$sig_orig =~ /((?&PerlAssignment)) ${grammar_re}/xg; |
85
|
|
|
|
|
|
|
|
86
|
10
|
|
|
|
|
1272
|
my (@sig_text, @defaults); |
87
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
62
|
foreach my $idx (0..$#sig_parts) { |
89
|
9
|
|
|
|
|
34
|
my $part = $sig_parts[$idx]; |
90
|
9
|
100
|
|
|
|
64
|
if ($part =~ s/^(\S+?)\s*=\s*(.*?)(,$|$)/$1$3/) { |
91
|
1
|
|
|
|
|
8
|
push @defaults, "$1 = $2 if \@_ <= $idx;"; |
92
|
|
|
|
|
|
|
} |
93
|
9
|
|
|
|
|
42
|
push @sig_text, $part; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
10
|
100
|
|
|
|
70
|
my $sig_text = |
97
|
|
|
|
|
|
|
@sig_text |
98
|
|
|
|
|
|
|
? 'my ('.(join ', ', @sig_text).') = @_;' |
99
|
|
|
|
|
|
|
: ''; |
100
|
10
|
|
|
|
|
40
|
my $code = join ' ', $sig_text, @defaults; |
101
|
10
|
|
|
|
|
145
|
$s->{body}->transform_text(sub { s/^{/{ ${code}/ }); |
|
10
|
|
|
|
|
96
|
|
102
|
10
|
100
|
|
|
|
64
|
if ($proto) { |
103
|
|
|
|
|
|
|
$s->{sig}->transform_text(sub { |
104
|
7
|
|
|
|
|
76
|
s/\A(\s*)\(.*\)(\s*)\Z/${1}${proto}${2}/; |
105
|
7
|
|
|
|
|
49
|
}); |
106
|
|
|
|
|
|
|
} else { |
107
|
3
|
|
|
|
|
13
|
$s->{sig}->replace_text(''); |
108
|
|
|
|
|
|
|
} |
109
|
9
|
|
|
|
|
124
|
}; |
110
|
9
|
|
|
|
|
45
|
$self->_transform_signatures($top, $tf); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _transform_signatures { |
114
|
11
|
|
|
11
|
|
32
|
my ($self, $top, $tf) = @_; |
115
|
11
|
|
|
|
|
72
|
my @common = ( |
116
|
|
|
|
|
|
|
'(?:', # 5.20, 5.28+ |
117
|
|
|
|
|
|
|
[ before => '(?: (?&PerlOWS) (?>(?&PerlAttributes)) )?+' ], |
118
|
|
|
|
|
|
|
[ sig => '(?&PerlOWS) (?&PerlParenthesesList)' ], # not optional for us |
119
|
|
|
|
|
|
|
[ after => '(?&PerlOWS)' ], |
120
|
|
|
|
|
|
|
'|', # 5.22 - 5.26 |
121
|
|
|
|
|
|
|
[ before => '(?&PerlOWS)' ], |
122
|
|
|
|
|
|
|
[ sig => '(?&PerlParenthesesList) (?&PerlOWS)' ], # not optional for us |
123
|
|
|
|
|
|
|
[ after => '(?: (?>(?&PerlAttributes)) (?&PerlOWS) )?+' ], |
124
|
|
|
|
|
|
|
')', |
125
|
|
|
|
|
|
|
[ body => '(?&PerlBlock)' ], |
126
|
|
|
|
|
|
|
); |
127
|
11
|
|
|
|
|
56
|
$top->each_match_within('SubroutineDeclaration' => [ |
128
|
|
|
|
|
|
|
'sub \b (?&PerlOWS) (?&PerlOldQualifiedIdentifier)', |
129
|
|
|
|
|
|
|
@common, |
130
|
|
|
|
|
|
|
], $tf); |
131
|
11
|
|
|
|
|
70
|
$top->each_match_within('AnonymousSubroutine' => [ |
132
|
|
|
|
|
|
|
'sub \b', |
133
|
|
|
|
|
|
|
@common, |
134
|
|
|
|
|
|
|
], $tf); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
__END__ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 NAME |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Babble::Plugin::CoreSignatures - Plugin for signatures feature |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SYNOPSIS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Supports converting from signatures syntax to plain C<@_> unpacking, for |
147
|
|
|
|
|
|
|
example from |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub foo :prototype($) ($sig) { } |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
to |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub foo ($) { my ($sig) = @_; } |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L<signatures feature|feature/"The 'signatures' feature"> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |