| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Run::Parts; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
297204
|
use Modern::Perl; |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
141
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=encoding utf8 |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Run::Parts - Offers functionality of Debian's run-parts tool in Perl. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.06 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
5
|
|
|
5
|
|
5479
|
use File::Slurp; |
|
|
5
|
|
|
|
|
87575
|
|
|
|
5
|
|
|
|
|
413
|
|
|
20
|
5
|
|
|
5
|
|
3154
|
use Run::Parts::Common; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
790
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Run::Parts offers functionality of Debian's run-parts tool in Perl. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
run-parts runs all the executable files named within constraints |
|
27
|
|
|
|
|
|
|
described in L and L, found |
|
28
|
|
|
|
|
|
|
in the given directory. Other files and directories are silently |
|
29
|
|
|
|
|
|
|
ignored. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Additionally it can just print the names of the all matching files |
|
32
|
|
|
|
|
|
|
(not limited to executables, but ignores blacklisted files like |
|
33
|
|
|
|
|
|
|
e.g. backup files), but don't actually run them. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This is useful when functionality or configuration is split over |
|
36
|
|
|
|
|
|
|
multiple files in one directory. A typical convention is that the |
|
37
|
|
|
|
|
|
|
directory name ends in ".d". Common examples for such splittet |
|
38
|
|
|
|
|
|
|
configuration directories: |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
/etc/cron.d/ |
|
41
|
|
|
|
|
|
|
/etc/apt/apt.conf.d/ |
|
42
|
|
|
|
|
|
|
/etc/apt/sources.list.d/, |
|
43
|
|
|
|
|
|
|
/etc/aptitude-robot/pkglist.d/ |
|
44
|
|
|
|
|
|
|
/etc/logrotate.d/ |
|
45
|
|
|
|
|
|
|
/etc/rsyslog.d/ |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Perhaps a little code snippet. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Run::Parts; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $rp = Run::Parts->new('directory'); # chooses backend automatically |
|
52
|
|
|
|
|
|
|
my $rpp = Run::Parts->new('directory', 'perl'); # pure perl backend |
|
53
|
|
|
|
|
|
|
my $rpd = Run::Parts->new('directory', 'debian'); # uses /bin/run-parts |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @file_list = $rp->list; |
|
56
|
|
|
|
|
|
|
my @executables_list = $rpp->test; |
|
57
|
|
|
|
|
|
|
my $commands_output = $rpd->run; |
|
58
|
|
|
|
|
|
|
... |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=begin readme |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
To install this module, run the following commands: |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
perl Build.PL |
|
67
|
|
|
|
|
|
|
./Build |
|
68
|
|
|
|
|
|
|
./Build test |
|
69
|
|
|
|
|
|
|
./Build install |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=end readme |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 BACKENDS |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Run::Parts contains two backend implementation. Run::Parts::Debian |
|
77
|
|
|
|
|
|
|
actually uses /bin/run-parts and Run::Parts::Perl is a pure Perl |
|
78
|
|
|
|
|
|
|
implementation of a basic set of run-parts' functionality. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Run::Parts::Debian may or may not work with RedHat's simplified |
|
81
|
|
|
|
|
|
|
shell-script based reimplementation of Debian's run-parts. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
By default Run::Parts uses Run::Parts::Debian if /bin/run-parts |
|
84
|
|
|
|
|
|
|
exists, Run::Parts::Perl otherwise. But you can also choose any of the |
|
85
|
|
|
|
|
|
|
backends explicitly. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=for readme stop |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 new (Constructor) |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Creates a new Run::Parts object. Takes one parameter, the directory on |
|
95
|
|
|
|
|
|
|
which run-parts should work. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub new { |
|
100
|
5
|
|
|
5
|
1
|
3381
|
my $self = {}; |
|
101
|
5
|
|
|
|
|
23
|
bless($self, shift); |
|
102
|
5
|
|
|
|
|
33
|
$self->{dir} = shift; |
|
103
|
|
|
|
|
|
|
|
|
104
|
5
|
|
|
|
|
14
|
my $backend = shift; |
|
105
|
5
|
100
|
|
|
|
23
|
if (defined $backend) { |
|
106
|
4
|
50
|
66
|
|
|
216
|
if (ref $backend) { |
|
|
|
100
|
33
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
$self->{backend} = $backend->new($self->{dir}); |
|
108
|
|
|
|
|
|
|
} elsif ($backend eq 'debian' or $backend eq 'run-parts') { |
|
109
|
5
|
|
|
5
|
|
2832
|
use Run::Parts::Debian; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
304
|
|
|
110
|
2
|
|
|
|
|
23
|
$self->{backend} = Run::Parts::Debian->new($self->{dir}); |
|
111
|
|
|
|
|
|
|
} elsif ($backend eq 'perl' or $backend eq 'module') { |
|
112
|
5
|
|
|
5
|
|
2872
|
use Run::Parts::Perl; |
|
|
5
|
|
|
|
|
17
|
|
|
|
5
|
|
|
|
|
2476
|
|
|
113
|
2
|
|
|
|
|
36
|
$self->{backend} = Run::Parts::Perl->new($self->{dir}); |
|
114
|
|
|
|
|
|
|
} else { |
|
115
|
0
|
|
|
|
|
0
|
warn "Unknown backend $backend in use"; |
|
116
|
0
|
|
|
|
|
0
|
require $backend; |
|
117
|
0
|
|
|
|
|
0
|
$self->{backend} = $backend->new($self->{dir}); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
} else { |
|
120
|
1
|
50
|
|
|
|
106
|
if (-x '/bin/run-parts') { |
|
121
|
1
|
|
|
|
|
20
|
$self->{backend} = Run::Parts::Debian->new($self->{dir}); |
|
122
|
|
|
|
|
|
|
} else { |
|
123
|
0
|
|
|
|
|
0
|
$self->{backend} = Run::Parts::Perl->new($self->{dir}); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
5
|
|
|
|
|
18
|
return $self; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 run_parts_command |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns the run-parts to run with the given command parameter |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub run_parts_command { |
|
137
|
31
|
|
|
31
|
1
|
73
|
my $self = shift; |
|
138
|
31
|
|
|
|
|
236
|
return $self->{backend}->run_parts_command(@_); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 list |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Lists all relevant files in the given directory. Equivalent to |
|
144
|
|
|
|
|
|
|
"run-parts --list". |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub list { |
|
149
|
16
|
|
|
16
|
1
|
8767
|
my $self = shift; |
|
150
|
16
|
|
|
|
|
64
|
return $self->run_parts_command('list'); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 test |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Lists all relevant executables in the given directory. Equivalent to |
|
156
|
|
|
|
|
|
|
"run-parts --test". |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub test { |
|
161
|
10
|
|
|
10
|
1
|
4996
|
my $self = shift; |
|
162
|
10
|
|
|
|
|
51
|
return $self->run_parts_command('test'); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 run |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Runs all relevant executables in the given directory. Equivalent to |
|
168
|
|
|
|
|
|
|
"run-parts". |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub run { |
|
173
|
5
|
|
|
5
|
1
|
38
|
my $self = shift; |
|
174
|
5
|
|
|
|
|
38
|
return $self->run_parts_command(); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 concat |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns the concatenated contents of all relevant files in the given |
|
180
|
|
|
|
|
|
|
directory. Equivalent to "cat `run-parts --list`". |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub concat { |
|
185
|
6
|
|
|
6
|
1
|
25
|
my $self = shift; |
|
186
|
6
|
|
|
|
|
32
|
return lines(map { read_file($_, { chomp => 1 }) } $self->list()); |
|
|
24
|
|
|
|
|
3793
|
|
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=for readme continue |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
run-parts(8), Run::Parts::Debian, Run::Parts::Perl |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Axel Beckert, C<< >> |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 BUGS |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
|
202
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
|
203
|
|
|
|
|
|
|
L. I will |
|
204
|
|
|
|
|
|
|
be notified, and then you'll automatically be notified of progress on |
|
205
|
|
|
|
|
|
|
your bug as I make changes. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 CODE |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
You can find a git repository of Run::Parts' code at |
|
211
|
|
|
|
|
|
|
L. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 SUPPORT |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=begin readme |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
perldoc Run::Parts |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
You can also look for information at: |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=end readme |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=over 4 |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
L |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
L |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item * Search CPAN |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
L |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=back |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Copyright 2013 Axel Beckert. |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
253
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
254
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
See L for more information. |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
1; # End of Run::Parts |