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