Util.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 96.4% 55 / 57 CC 4 SCAR 6.9
CC
4
Cov
96%
import
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« Util/File.pm ↑ Summary Util/Syntax.pm »
1 package Dev::Util;
2  
3 4 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = version->declare("v2.19.42");
10  
11 4 ▶use Exporter qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use List::Util qw( uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 our @EXPORT = ();
15 4 our @EXPORT_OK = ();
16 4 our %EXPORT_TAGS = ( all => \@EXPORT_OK ); # Optional.
17  
18 4 ▶sub import {
Subroutine import: called CC=4 SCAR=13.9
19 4 my $class = shift;
20 4 my (@packages) = @_;
21  
22 4 my ( @pkgs, @rest );
23 4 for (@packages) {
24 7 ▶ if (/^::/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^::/u) { } 7 0 7
25 7 push @pkgs, __PACKAGE__ . $_;
26 }
27 else {
28 0 push @rest, $_;
29 }
30 }
31  
32 4 for my $pkg (@pkgs) {
33 7 my $mod = ( $pkg =~ s{::}{/}gr ) . ".pm";
34 7 require $mod;
35  
36 4 ▶ my $exports = do { no strict "refs"; \@{ $pkg . "::EXPORT_OK" } };
Subroutine BEGIN: called CC=1 SCAR=0.0
37 7 $pkg->import(@$exports);
38 7 @EXPORT = uniq @EXPORT, @$exports;
39 7 @EXPORT_OK = uniq @EXPORT_OK, @$exports;
40 }
41  
42 4 @_ = ( $class, @rest );
43 4 goto &Exporter::import;
44 }
45  
46 4 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.42
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-2026 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__
« Util/File.pm ↑ Summary Util/Syntax.pm »