line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::FileSummoner::Register; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
2239
|
$App::FileSummoner::Register::VERSION = '0.005'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
26
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
App::FileSummoner::Register - Skeletons register |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my ( @rules, %skeleton ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
registerSkeleton(qr/\.pm$/, 'perl/skeleton.pm'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $skeleton = chooseSkeleton('some/path/Module.pm'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 EXPORT |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over 2 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item registerSkeleton |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item chooseSkeleton |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=back |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
6
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
409
|
|
37
|
|
|
|
|
|
|
our @EXPORT_OK = qw(registerSkeleton chooseSkeleton); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SUBROUTINES |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 registerSkeleton |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Register new skeleton for a given rule. Use in I<rules.pl> file. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub registerSkeleton { |
48
|
0
|
|
|
0
|
1
|
|
my ( $rule, $skeleton ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
return if defined $skeleton{$rule}; |
51
|
0
|
|
|
|
|
|
push @rules, $rule; |
52
|
0
|
|
|
|
|
|
$skeleton{$rule} = $skeleton; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 chooseSkeleton |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Choose the best skeleton for a given file. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub chooseSkeleton { |
62
|
0
|
|
|
0
|
1
|
|
my ($fileName) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $rule (@rules) { |
65
|
0
|
0
|
|
|
|
|
return $skeleton{$rule} if ruleMatches( $rule, $fileName ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return undef; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 unregisterAll |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub unregisterAll { |
76
|
0
|
|
|
0
|
1
|
|
@rules = (); |
77
|
0
|
|
|
|
|
|
%skeleton = (); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 ruleMatches |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Check if a filename matches a given rule. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub ruleMatches { |
87
|
0
|
|
|
0
|
1
|
|
my ( $rule, $fileName ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
return rulesMatches( $rule, $fileName ) if ref $rule eq 'ARRAY'; |
90
|
0
|
0
|
|
|
|
|
return &$rule($fileName) if ref $rule eq 'CODE'; |
91
|
0
|
|
|
|
|
|
return $fileName =~ $rule; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub rulesMatches { |
95
|
0
|
|
|
0
|
0
|
|
my ( $rulesRef, $fileName ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
foreach my $rule (@{ $rulesRef }) { |
|
0
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
ruleMatches($rule, $fileName) || return 0; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
return 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |