| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dev::Util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
137015
|
use 5.018; |
|
|
4
|
|
|
|
|
28
|
|
|
4
|
4
|
|
|
4
|
|
43
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
110
|
|
|
5
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
225
|
|
|
6
|
4
|
|
|
4
|
|
37
|
use version; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
24
|
|
|
7
|
4
|
|
|
4
|
|
422
|
use Carp qw(carp); |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
349
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = version->declare("v2.19.35"); |
|
10
|
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
23
|
use Exporter qw( ); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
115
|
|
|
12
|
4
|
|
|
4
|
|
37
|
use List::Util qw( uniq ); |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
1149
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = (); |
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = (); |
|
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); # Optional. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
|
19
|
4
|
|
|
4
|
|
41
|
my $class = shift; |
|
20
|
4
|
|
|
|
|
13
|
my (@packages) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
8
|
my ( @pkgs, @rest ); |
|
23
|
4
|
|
|
|
|
12
|
for (@packages) { |
|
24
|
7
|
50
|
|
|
|
23
|
if (/^::/) { |
|
25
|
7
|
|
|
|
|
19
|
push @pkgs, __PACKAGE__ . $_; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
else { |
|
28
|
0
|
|
|
|
|
0
|
push @rest, $_; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
9
|
for my $pkg (@pkgs) { |
|
33
|
7
|
|
|
|
|
56
|
my $mod = ( $pkg =~ s{::}{/}gr ) . ".pm"; |
|
34
|
7
|
|
|
|
|
4161
|
require $mod; |
|
35
|
|
|
|
|
|
|
|
|
36
|
4
|
|
|
4
|
|
60
|
my $exports = do { no strict "refs"; \@{ $pkg . "::EXPORT_OK" } }; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
996
|
|
|
|
7
|
|
|
|
|
31
|
|
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
36
|
|
|
37
|
7
|
|
|
|
|
499
|
$pkg->import(@$exports); |
|
38
|
7
|
|
|
|
|
126
|
@EXPORT = uniq @EXPORT, @$exports; |
|
39
|
7
|
|
|
|
|
107
|
@EXPORT_OK = uniq @EXPORT_OK, @$exports; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
13
|
@_ = ( $class, @rest ); |
|
43
|
4
|
|
|
|
|
891
|
goto &Exporter::import; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; # End of Dev::Util |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=encoding utf-8 |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Dev::Util - Utilities useful in the development of perl programs |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Version v2.19.35 |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This module provides a standard set of tools to use for oft needed functionality. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Consistent feature setup is achieved. |
|
65
|
|
|
|
|
|
|
Standard constants are defined. OS identification and external executables are |
|
66
|
|
|
|
|
|
|
accessible. Quick backups can be made. File and directory attributes are discovered. |
|
67
|
|
|
|
|
|
|
Lock files are created. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The sub-modules provide this and other utility functionality. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SUB-MODULES |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The sub-modules provide the functionality described below. For more details |
|
74
|
|
|
|
|
|
|
see C<<< perldoc <Sub-module_Name> >>>. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 Dev::Util |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
C<Dev::Util> provides a loader for sub-modules where a leading C<::> denotes |
|
80
|
|
|
|
|
|
|
a package to load. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Dev::Util qw( ::File ::OS ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This is equivalent to: |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use Dev::Util::File qw(:all); |
|
87
|
|
|
|
|
|
|
use Dev::Util::OS qw(:all); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# =head2 How it works |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# The Dev::Util module simply imports functions from Dev::Util::* |
|
94
|
|
|
|
|
|
|
# modules. Each module defines a self-contained functions, and puts |
|
95
|
|
|
|
|
|
|
# those function names into @EXPORT. Dev::Util defines its own |
|
96
|
|
|
|
|
|
|
# import function, but that does not matter to the plug-in modules. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# This function is taken from brian d foy's Test::Data module. Thanks brian! |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Dev::Util::Syntax |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Provide consistent feature setup. Put all of the "use" setup cmds in one |
|
103
|
|
|
|
|
|
|
place. Then import them into other modules. Changes are made in one place, yet apply |
|
104
|
|
|
|
|
|
|
to all of the programs that use C<Dev::Util::Syntax> |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Use this in other modules: |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
package My::Module::Example; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
use Dev::Util::Syntax; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Rest of Code... |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This is equivalent to: |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
package My::Module::Example; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
use feature :5.18; |
|
119
|
|
|
|
|
|
|
use utf8; |
|
120
|
|
|
|
|
|
|
use strict; |
|
121
|
|
|
|
|
|
|
use warnings; |
|
122
|
|
|
|
|
|
|
use autodie; |
|
123
|
|
|
|
|
|
|
use open qw(:std :utf8); |
|
124
|
|
|
|
|
|
|
use version; |
|
125
|
|
|
|
|
|
|
use Readonly; |
|
126
|
|
|
|
|
|
|
use Carp; |
|
127
|
|
|
|
|
|
|
use English qw( -no_match_vars ); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Rest of Code... |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
B<Note: C<use Dev::Util::Syntax> automatically adds C<use strict> and C<use warnings> to the program.> |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Dev::Util::Syntax> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 Dev::Util::Const |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Defines named constants as Readonly, based on best practices. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$EMPTY_STR = q{}; |
|
140
|
|
|
|
|
|
|
$SPACE = q{ }; |
|
141
|
|
|
|
|
|
|
$SINGLE_QUOTE = q{'}; |
|
142
|
|
|
|
|
|
|
$DOUBLE_QUOTE = q{"}; |
|
143
|
|
|
|
|
|
|
$COMMA = q{,}; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<Dev::Util::Const> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 Dev::Util::OS |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
OS discovery and functions to execute and collect data from external programs. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
use Dev::Util::OS; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $OS = get_os(); |
|
154
|
|
|
|
|
|
|
my $hostname = get_hostname(); |
|
155
|
|
|
|
|
|
|
my $system_is_linux = is_linux(); |
|
156
|
|
|
|
|
|
|
my @seq = ipc_run_c( { cmd => 'seq 1 10', } ); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Dev::Util::OS> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 Dev::Util::File |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Provides functions to assist working with files and dirs, menus and prompts. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
use Dev::Util::File; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $fexists = file_exists('/path/to/somefile'); |
|
167
|
|
|
|
|
|
|
my $canwritef = file_writable('/path/to/somefile'); |
|
168
|
|
|
|
|
|
|
my $isplainfile = file_is_plain('/path/to/somefile'); |
|
169
|
|
|
|
|
|
|
my $issymlink = file_is_symbolic_link('/path/to/somefile'); |
|
170
|
|
|
|
|
|
|
my $canreadd = dir_readable('/path/to/somedir'); |
|
171
|
|
|
|
|
|
|
my $slash_added_dir = dir_suffix_slash('/dir/path/no/slash'); |
|
172
|
|
|
|
|
|
|
my $td = mk_temp_dir(); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L<Dev::Util::File> |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 Dev::Util::Query |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Provides functions to ask the user for input. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
banner( "Hello World", $outputFH ); |
|
181
|
|
|
|
|
|
|
display_menu( $msg, \@items ); |
|
182
|
|
|
|
|
|
|
my $action = yes_no_prompt( { text => "Rename Files?", default => 1, }); |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L<Dev::Util::Query> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 Dev::Util::Backup |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The backup function will make a copy of a file or dir with the date of the file |
|
189
|
|
|
|
|
|
|
appended. Directories are backed up by tar and gz. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
my $backup_file = backup('myfile'); |
|
192
|
|
|
|
|
|
|
my $backup_dir = backup('mydir/'); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L<Dev::Util::Backup> |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 Dev::Util::Sem |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Module to do Semaphore locking |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
use Dev::Util::Sem; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my $sem = Sem->new('mylock.sem'); |
|
203
|
|
|
|
|
|
|
... |
|
204
|
|
|
|
|
|
|
$sem->unlock; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L<Dev::Util::Sem> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 EXAMPLES |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Example programs that demonstrate how the C<Dev::Util> modules can be used are in the C<examples> dir. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L<Dev::Util::Backup>, |
|
216
|
|
|
|
|
|
|
L<Dev::Util::Const>, |
|
217
|
|
|
|
|
|
|
L<Dev::Util::File>, |
|
218
|
|
|
|
|
|
|
L<Dev::Util::OS>, |
|
219
|
|
|
|
|
|
|
L<Dev::Util::Query> |
|
220
|
|
|
|
|
|
|
L<Dev::Util::Syntax>, |
|
221
|
|
|
|
|
|
|
L<Dev::Util::Sem>, |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Matt Martini, C<< <matt.martini at imaginarywave.com> >> |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 BUGS |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-dev-util at rt.cpan.org>, or through |
|
231
|
|
|
|
|
|
|
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dev-Util>. I will be notified, and then you'll |
|
232
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
To install this module, see F<INSTALL.md> |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
TLDR; run the following commands: |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
perl Makefile.PL |
|
241
|
|
|
|
|
|
|
make |
|
242
|
|
|
|
|
|
|
make test |
|
243
|
|
|
|
|
|
|
make install |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 SUPPORT AND DOCUMENTATION |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
perldoc Dev::Util |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
You can also look for information at: |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=over 4 |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Dev-Util> |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item * Search CPAN |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
L<https://metacpan.org/release/Dev-Util> |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=back |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 HISTORY |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This module was originally developed under the name C<MERM::Base>. |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 TEMPLATE |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
module-starter \ |
|
273
|
|
|
|
|
|
|
--module=Dev::Util \ |
|
274
|
|
|
|
|
|
|
--module=Dev::Util::Backup \ |
|
275
|
|
|
|
|
|
|
--module=Dev::Util::Const \ |
|
276
|
|
|
|
|
|
|
--module=Dev::Util::File \ |
|
277
|
|
|
|
|
|
|
--module=Dev::Util::OS \ |
|
278
|
|
|
|
|
|
|
--module=Dev::Util::Query \ |
|
279
|
|
|
|
|
|
|
--module=Dev::Util::Sem \ |
|
280
|
|
|
|
|
|
|
--module=Dev::Util::Syntax \ |
|
281
|
|
|
|
|
|
|
--builder=ExtUtils::MakeMaker \ |
|
282
|
|
|
|
|
|
|
--author='Matt Martini' \ |
|
283
|
|
|
|
|
|
|
--email=matt@imaginarywave.com \ |
|
284
|
|
|
|
|
|
|
--ignore=git \ |
|
285
|
|
|
|
|
|
|
--license=gpl3 \ |
|
286
|
|
|
|
|
|
|
--genlicense \ |
|
287
|
|
|
|
|
|
|
--minperl=5.018 \ |
|
288
|
|
|
|
|
|
|
--verbose |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 ACKNOWLEDGMENTS |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
This software is Copyright © 2024-2025 by Matt Martini. |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
This is free software, licensed under: |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
__END__ |
|
303
|
|
|
|
|
|
|
|