line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
57807
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Provides a function keyword |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Syntax::Feature::Function; |
7
|
|
|
|
|
|
|
{ |
8
|
|
|
|
|
|
|
$Syntax::Feature::Function::VERSION = '0.002'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
39
|
|
12
|
1
|
|
|
1
|
|
906
|
use Function::Parameters (); |
|
1
|
|
|
|
|
2226
|
|
|
1
|
|
|
|
|
18
|
|
13
|
1
|
|
|
1
|
|
5
|
use B::Hooks::EndOfScope; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
14
|
1
|
|
|
1
|
|
722
|
use Import::Into; |
|
1
|
|
|
|
|
387
|
|
|
1
|
|
|
|
|
22
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$Carp::Internal{ +__PACKAGE__ }++; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub install { |
21
|
3
|
|
|
3
|
1
|
269
|
my ($class, %args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
5
|
my $target = $args{into}; |
24
|
3
|
|
|
|
|
4
|
my $options = $args{options}; |
25
|
3
|
|
|
|
|
5
|
my @names = qw( fun ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# we received options |
28
|
3
|
100
|
|
|
|
9
|
if (defined $options) { |
29
|
2
|
|
|
|
|
3
|
my $options_ref = ref $options; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# function => { ... } |
32
|
2
|
50
|
|
|
|
6
|
if ($options_ref eq 'HASH') { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# function => { -as => ... } |
35
|
2
|
50
|
|
|
|
6
|
if (defined( my $as = $options->{ -as } )) { |
36
|
2
|
|
|
|
|
4
|
my $as_ref = ref $as; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# -as => 'fun' |
39
|
2
|
100
|
|
|
|
18
|
if (not $as_ref) { |
|
|
50
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
3
|
@names = ($as); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# -as => [qw( fun f )] |
45
|
|
|
|
|
|
|
elsif (ref $as eq 'ARRAY') { |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
4
|
@names = @$as; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# bad -as type |
51
|
|
|
|
|
|
|
else { |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
croak q(The '-as' option to the 'function' syntax feature only accepts) |
54
|
|
|
|
|
|
|
. q( scalar and array reference values); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# bad options type |
60
|
|
|
|
|
|
|
else { |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
croak q(Options for feature must be a hash or array reference); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# make sure all names are valid |
67
|
|
|
|
|
|
|
m/\A[_a-z][_a-z0-9]*\Z/i |
68
|
|
|
|
|
|
|
or croak qq(Invalid function declaration identifier '$_') |
69
|
3
|
|
50
|
|
|
18
|
for @names; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# install handlers |
72
|
|
|
|
|
|
|
Function::Parameters->import::into($target, $_) |
73
|
3
|
|
|
|
|
16
|
for @names; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
on_scope_end { |
76
|
3
|
|
|
3
|
|
731
|
namespace::clean->clean_subroutines($target, @names); |
77
|
3
|
|
|
|
|
1175
|
}; |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
39
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |