line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filter::EOF; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Filter::EOF - Run a callback after a file has been compiled |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
60534
|
use warnings; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
143
|
|
10
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
235
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
0.04 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.04; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package MyPackage; |
23
|
|
|
|
|
|
|
use warnings; |
24
|
|
|
|
|
|
|
use strict; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Filter::EOF; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub import { |
29
|
|
|
|
|
|
|
my ($class, @args) = @_; |
30
|
|
|
|
|
|
|
my $caller = scalar caller; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# set the COMPILE_TIME package var to a false value |
33
|
|
|
|
|
|
|
# when the file was compiled |
34
|
|
|
|
|
|
|
Filter::EOF->on_eof_call(sub { |
35
|
|
|
|
|
|
|
no strict 'refs'; |
36
|
|
|
|
|
|
|
${ $caller . '::COMPILE_TIME' } = 0; |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# set the COMPILE_TIME package var to a true value when |
40
|
|
|
|
|
|
|
# we start compiling it. |
41
|
|
|
|
|
|
|
{ no strict 'refs'; |
42
|
|
|
|
|
|
|
${ $caller . '::COMPILE_TIME' } = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
... |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package MyUsingPackage; |
50
|
|
|
|
|
|
|
use warnings; |
51
|
|
|
|
|
|
|
use strict; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
our $COMPILE_TIME; |
54
|
|
|
|
|
|
|
use MyPackage; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# prints 'yes' |
57
|
|
|
|
|
|
|
BEGIN { print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n" } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# prints 'no' |
60
|
|
|
|
|
|
|
print +( $COMPILE_TIME ? 'yes' : 'no' ), "\n"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This module utilises Perl's source filters to provide you with a |
67
|
|
|
|
|
|
|
mechanism to run some code after a file using your module has been |
68
|
|
|
|
|
|
|
processed. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
4
|
|
35
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
333
|
|
73
|
4
|
|
|
4
|
|
6608
|
use Filter::Util::Call; |
|
4
|
|
|
|
|
6167
|
|
|
4
|
|
|
|
|
2047
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 C |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Currently, only a function equivalent of the C method |
80
|
|
|
|
|
|
|
is provided for export. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Filter::EOF qw( on_eof_call ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub import { |
85
|
|
|
|
|
|
|
my ($class) = @_; |
86
|
|
|
|
|
|
|
... |
87
|
|
|
|
|
|
|
on_eof_call { ... }; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
... |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my %Export = ( |
94
|
1
|
|
|
1
|
|
17
|
on_eof_call => sub { my $class = shift; sub (&) { $class->on_eof_call(@_) } }, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub import { |
98
|
4
|
|
|
4
|
|
37
|
my ($class, @names) = @_; |
99
|
4
|
|
|
|
|
13
|
for my $name (@names) { |
100
|
1
|
50
|
|
|
|
6
|
Carp::croak "Unknown function '$name'" unless exists $Export{ $name }; |
101
|
4
|
|
|
4
|
|
33
|
no strict 'refs'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
948
|
|
102
|
1
|
|
|
|
|
3
|
*{ scalar(caller) . '::' . $name } = $Export{ $name }->($class); |
|
1
|
|
|
|
|
8
|
|
103
|
|
|
|
|
|
|
} |
104
|
4
|
|
|
|
|
124
|
return 1; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 C |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Call this method in your own C method to register a code |
110
|
|
|
|
|
|
|
reference that should be called when the file C |
111
|
|
|
|
|
|
|
compiled. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
The code reference will get a scalar reference as first argument |
114
|
|
|
|
|
|
|
to an empty string. if you change this string to something else, |
115
|
|
|
|
|
|
|
it will be appended at the end of the source. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# call C after runtime. |
118
|
|
|
|
|
|
|
Filter->on_eof_call(sub { |
119
|
|
|
|
|
|
|
my $append = shift; |
120
|
|
|
|
|
|
|
$$append .= '; some_function(); 1;'; |
121
|
|
|
|
|
|
|
}); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub on_eof_call { |
126
|
3
|
|
|
3
|
1
|
663
|
my ($class, $code) = @_; |
127
|
|
|
|
|
|
|
|
128
|
3
|
|
|
|
|
6
|
my $past_eof; |
129
|
|
|
|
|
|
|
filter_add( sub { |
130
|
23
|
|
|
23
|
|
353
|
my $status = filter_read; |
131
|
23
|
100
|
|
|
|
2007
|
return $status if $past_eof; |
132
|
20
|
100
|
|
|
|
42
|
if ($status == 0) { |
133
|
3
|
|
|
|
|
62
|
$code->(\$_); |
134
|
3
|
|
|
|
|
17
|
$status = 1; |
135
|
3
|
|
|
|
|
5
|
$past_eof = 1; |
136
|
|
|
|
|
|
|
} |
137
|
20
|
|
|
|
|
219
|
return $status; |
138
|
3
|
|
|
|
|
21
|
}); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 EXPORTS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 on_eof_call |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
You can optionally import the C function into your namespace. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 EXAMPLES |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can find the example mentioned in L in the distribution |
150
|
|
|
|
|
|
|
directory C. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L, |
155
|
|
|
|
|
|
|
L |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR AND COPYRIGHT |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Robert 'phaylon' Sedlacek - Crs@474.atE>. Many thanks to |
160
|
|
|
|
|
|
|
Matt S Trout for the idea and inspirations on this module. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
165
|
|
|
|
|
|
|
it under the same terms as perl itself. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |