line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::ModuleByFile; ## Can read the module name from file |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
4425
|
use 5.006; |
|
4
|
|
|
|
|
10
|
|
4
|
4
|
|
|
4
|
|
14
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
80
|
|
5
|
4
|
|
|
4
|
|
1774
|
use FileHandle; |
|
4
|
|
|
|
|
30558
|
|
|
4
|
|
|
|
|
19
|
|
6
|
4
|
|
|
4
|
|
996
|
use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
254
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
12
|
use Exporter; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1168
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [qw( |
15
|
|
|
|
|
|
|
get_name |
16
|
|
|
|
|
|
|
get_module_by_file |
17
|
|
|
|
|
|
|
get_parent |
18
|
|
|
|
|
|
|
)] ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Exporter::export_ok_tags('all'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# You can use that class to get the module name (package) by filename. |
23
|
|
|
|
|
|
|
# It reads the file and returns the package entry. |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# SYNOPSIS |
27
|
|
|
|
|
|
|
# ======== |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# use Class::ModuleByFile; |
30
|
|
|
|
|
|
|
# print Class::ModuleByFile::get_name('/tmp/Local/Bar.pm'); |
31
|
|
|
|
|
|
|
# # may print 'Local::Bar' |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# use Class::ModuleByFile 'get_module_by_file'; |
34
|
|
|
|
|
|
|
# # imports the function get_module_by_file() |
35
|
|
|
|
|
|
|
# # to use it directly. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
# LICENSE |
38
|
|
|
|
|
|
|
# ======= |
39
|
|
|
|
|
|
|
# You can redistribute it and/or modify it under the conditions of LGPL. |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# AUTHOR |
42
|
|
|
|
|
|
|
# ====== |
43
|
|
|
|
|
|
|
# Andreas Hernitscheck ahernit(AT)cpan.org |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Returns the modulename for the given file. |
52
|
|
|
|
|
|
|
# It reads the text of the file and returns |
53
|
|
|
|
|
|
|
# the package entry |
54
|
|
|
|
|
|
|
sub get_name { # $modulename ($filename) |
55
|
2
|
50
|
|
2
|
1
|
45
|
my $file = shift or die 'requires filename'; |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
16
|
if (!-e $file){die "file $file does not exist"}; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
20
|
my $fh = FileHandle->new($file, "r"); |
60
|
2
|
50
|
|
|
|
205
|
if (defined $fh) { |
61
|
2
|
|
|
|
|
42
|
while (my $line = <$fh>){ |
62
|
|
|
|
|
|
|
|
63
|
2
|
50
|
|
|
|
14
|
if ( $line=~ m/\s*package\s+([^ ;]+)/ ){ |
64
|
2
|
|
|
|
|
22
|
return $1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
$fh->close(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# alias for get_name() |
75
|
|
|
|
|
|
|
sub get_module_by_file { |
76
|
1
|
|
|
1
|
1
|
44
|
return get_name(@_); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# If Moose is used and extend to set a parent, |
81
|
|
|
|
|
|
|
# it reads that entry. |
82
|
|
|
|
|
|
|
sub get_parent { |
83
|
1
|
50
|
|
1
|
0
|
31
|
my $file = shift or die 'requires filename'; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
8
|
if (!-e $file){die "file $file does not exist"}; |
|
0
|
|
|
|
|
0
|
|
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
8
|
my $fh = FileHandle->new($file, "r"); |
88
|
1
|
50
|
|
|
|
95
|
if (defined $fh) { |
89
|
1
|
|
|
|
|
16
|
while (my $line = <$fh>){ |
90
|
|
|
|
|
|
|
|
91
|
3
|
100
|
|
|
|
12
|
if ( $line=~ m/\s*extends\s+['"]([^ '"]+)['"]/ ){ |
92
|
1
|
|
|
|
|
11
|
return $1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$fh->close(); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Class::ModuleByFile - Can read the module name from file |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use Class::ModuleByFile; |
117
|
|
|
|
|
|
|
print Class::ModuleByFile::get_name('/tmp/Local/Bar.pm'); |
118
|
|
|
|
|
|
|
# may print 'Local::Bar' |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use Class::ModuleByFile 'get_module_by_file'; |
121
|
|
|
|
|
|
|
# imports the function get_module_by_file() |
122
|
|
|
|
|
|
|
# to use it directly. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
You can use that class to get the module name (package) by filename. |
129
|
|
|
|
|
|
|
It reads the file and returns the package entry. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 REQUIRES |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<5.006> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 METHODS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 get_module_by_file |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
get_module_by_file(); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
alias for get_name() |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 get_name |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $modulename = get_name($filename); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Returns the modulename for the given file. |
157
|
|
|
|
|
|
|
It reads the text of the file and returns |
158
|
|
|
|
|
|
|
the package entry |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Andreas Hernitscheck ahernit(AT)cpan.org |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 LICENSE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
You can redistribute it and/or modify it under the conditions of LGPL. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|