| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Babble::Plugin::CoreSignatures; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
69350
|
use strictures 2; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
51
|
|
|
4
|
1
|
|
|
1
|
|
761
|
use Moo; |
|
|
1
|
|
|
|
|
7243
|
|
|
|
1
|
|
|
|
|
7
|
|
|
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
|
1968
|
my ($self, $top) = @_; |
|
16
|
|
|
|
|
|
|
my $tf = sub { |
|
17
|
4
|
|
|
4
|
|
103
|
my $s = (my $m = shift)->submatches; |
|
18
|
4
|
100
|
|
|
|
44
|
if ((my $after = $s->{after}->text) =~ /\S/) { |
|
19
|
2
|
|
|
|
|
18
|
$s->{after}->replace_text(''); |
|
20
|
2
|
|
|
|
|
16
|
$s->{before}->replace_text($s->{before}->text.$after); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
1
|
|
|
|
|
7
|
}; |
|
23
|
1
|
|
|
|
|
6
|
$self->_transform_signatures($top, $tf); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub transform_to_oldsignatures { |
|
27
|
1
|
|
|
1
|
0
|
932
|
my ($self, $top) = @_; |
|
28
|
|
|
|
|
|
|
my $tf = sub { |
|
29
|
4
|
|
|
4
|
|
73
|
my $s = (my $m = shift)->submatches; |
|
30
|
4
|
100
|
|
|
|
34
|
if ((my $before = $s->{before}->text) =~ /\S/) { |
|
31
|
2
|
|
|
|
|
10
|
$s->{before}->replace_text(''); |
|
32
|
2
|
|
|
|
|
18
|
$s->{after}->replace_text($before.$s->{after}->text); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
1
|
|
|
|
|
7
|
}; |
|
35
|
1
|
|
|
|
|
5
|
$self->_transform_signatures($top, $tf); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub transform_to_plain { |
|
39
|
9
|
|
|
9
|
0
|
8752
|
my ($self, $top) = @_; |
|
40
|
9
|
|
|
|
|
52
|
$top->remove_use_argument(experimental => 'signatures'); |
|
41
|
9
|
|
|
|
|
107
|
$top->remove_use_argument('Mojo::Base' => '-signatures', 1); |
|
42
|
|
|
|
|
|
|
my $tf = sub { |
|
43
|
10
|
|
|
10
|
|
205
|
my $s = (my $m = shift)->submatches; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# shift attributes after first before we go hunting for :prototype |
|
46
|
10
|
100
|
|
|
|
95
|
if ((my $before = $s->{before}->text) =~ /\S/) { |
|
47
|
8
|
|
|
|
|
45
|
$s->{before}->replace_text(''); |
|
48
|
8
|
|
|
|
|
56
|
$s->{after}->replace_text($before.$s->{after}->text); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
10
|
|
|
|
|
38
|
my $proto = ''; |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
10
|
|
|
|
|
26
|
my $try = $s->{after}; |
|
|
10
|
|
|
|
|
18
|
|
|
54
|
10
|
|
|
|
|
31
|
local $try->{top_rule} = 'Attributes'; |
|
55
|
10
|
|
|
|
|
186
|
my $grammar = $m->grammar->clone; |
|
56
|
10
|
|
|
|
|
1144
|
$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
|
|
|
|
|
30
|
local $try->{grammar} = $grammar; |
|
65
|
10
|
|
|
|
|
21
|
my $each; $each = sub { |
|
66
|
14
|
|
|
|
|
38
|
my ($attr) = @_; |
|
67
|
14
|
100
|
|
|
|
103
|
if ($attr->text =~ /prototype(\(.*?\))/) { |
|
68
|
7
|
|
|
|
|
26
|
$proto = $1; |
|
69
|
7
|
|
|
|
|
34
|
$attr->replace_text(''); |
|
70
|
|
|
|
|
|
|
$each = sub { |
|
71
|
2
|
|
|
|
|
12
|
my ($attr) = @_; |
|
72
|
2
|
50
|
|
|
|
25
|
$attr->transform_text(sub { s/^(\s*)/${1}:/ }) unless $attr->text =~ /^\s*:/; |
|
|
2
|
|
|
|
|
28
|
|
|
73
|
2
|
|
|
|
|
15
|
$each = sub {}; |
|
74
|
7
|
|
|
|
|
59
|
}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
10
|
|
|
|
|
61
|
}; |
|
77
|
10
|
|
|
|
|
76
|
$try->each_match_of(Attribute => sub { $each->(@_) }); |
|
|
16
|
|
|
|
|
57
|
|
|
78
|
10
|
|
|
|
|
221
|
undef($each); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
147
|
s/\A\s*\(//, s/\)\s*\Z// for my $sig_orig = $s->{sig}->text; |
|
82
|
10
|
|
|
|
|
227
|
my $grammar_re = $m->grammar_regexp; |
|
83
|
10
|
|
|
|
|
384624
|
my @sig_parts = grep defined($_), |
|
84
|
|
|
|
|
|
|
$sig_orig =~ /((?&PerlAssignment)) ${grammar_re}/xg; |
|
85
|
|
|
|
|
|
|
|
|
86
|
10
|
|
|
|
|
1816
|
my (@sig_text, @defaults); |
|
87
|
|
|
|
|
|
|
|
|
88
|
10
|
|
|
|
|
86
|
foreach my $idx (0..$#sig_parts) { |
|
89
|
9
|
|
|
|
|
40
|
my $part = $sig_parts[$idx]; |
|
90
|
9
|
100
|
|
|
|
76
|
if ($part =~ s/^(\S+?)\s*=\s*(.*?)(,$|$)/$1$3/) { |
|
91
|
1
|
|
|
|
|
8
|
push @defaults, "$1 = $2 if \@_ <= $idx;"; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
9
|
|
|
|
|
50
|
push @sig_text, $part; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
10
|
100
|
|
|
|
91
|
my $sig_text = |
|
97
|
|
|
|
|
|
|
@sig_text |
|
98
|
|
|
|
|
|
|
? 'my ('.(join ', ', @sig_text).') = @_;' |
|
99
|
|
|
|
|
|
|
: ''; |
|
100
|
10
|
|
|
|
|
41
|
my $code = join ' ', $sig_text, @defaults; |
|
101
|
10
|
|
|
|
|
255
|
$s->{body}->transform_text(sub { s/^{/{ ${code}/ }); |
|
|
10
|
|
|
|
|
119
|
|
|
102
|
10
|
100
|
|
|
|
71
|
if ($proto) { |
|
103
|
|
|
|
|
|
|
$s->{sig}->transform_text(sub { |
|
104
|
7
|
|
|
|
|
88
|
s/\A(\s*)\(.*\)(\s*)\Z/${1}${proto}${2}/; |
|
105
|
7
|
|
|
|
|
54
|
}); |
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
3
|
|
|
|
|
16
|
$s->{sig}->replace_text(''); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
9
|
|
|
|
|
128
|
}; |
|
110
|
9
|
|
|
|
|
64
|
$self->_transform_signatures($top, $tf); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _transform_signatures { |
|
114
|
11
|
|
|
11
|
|
36
|
my ($self, $top, $tf) = @_; |
|
115
|
11
|
|
|
|
|
91
|
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
|
|
|
|
|
59
|
$top->each_match_within('SubroutineDeclaration' => [ |
|
128
|
|
|
|
|
|
|
'sub \b (?&PerlOWS) (?&PerlOldQualifiedIdentifier)', |
|
129
|
|
|
|
|
|
|
@common, |
|
130
|
|
|
|
|
|
|
], $tf); |
|
131
|
11
|
|
|
|
|
77
|
$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 |