1Test2::Harness::Util(3)User Contributed Perl DocumentatioTnest2::Harness::Util(3)
2
3
4

NAME

6       Test2::Harness::Util - General utiliy functions.
7

DESCRIPTION

METHODS

10   MISC
11       apply_encoding($fh, $enc)
12           Apply the specified encoding to the filehandle.
13
14           Justification: PERLBUG 31923
15           <https://rt.perl.org/Public/Bug/Display.html?id=31923> If utf8 is
16           requested we use ':utf8' instead of ':encoding(utf8)' in order to
17           avoid the thread segfault.
18
19           This is a reusable implementation of this:
20
21               sub apply_encoding {
22                   my ($fh, $enc) = @_;
23                   return unless $enc;
24                   return binmode($fh, ":utf8") if $enc =~ m/^utf-?8$/i;
25                   binmode($fh, ":encoding($enc)");
26               }
27
28       $clean = clean_path($path)
29           Take a file path and clean it up to a minimal absolute path if
30           possible. Always returns a path, but if it cannot be cleaned up it
31           is unchanged.
32
33       $hashref = find_libraries($search)
34       $hashref = find_libraries($search, @paths)
35           @INC is used if no @paths are provided.
36
37           $search should be a module name with "*" wildcards replacing
38           sections.
39
40               find_libraries('Foo::*::Baz')
41               find_libraries('*::Bar::Baz')
42               find_libraries('Foo::Bar::*')
43
44           These all look for modules matching the search, this is a good way
45           to find plugins, or similar patterns.
46
47           The result is a hashref of "{ $module => $path }". If a module
48           exists in more than 1 search path the first is used.
49
50       $mod = fqmod($prefix, $mod)
51           This will automatically add $prefix to $mod with '::' to join them.
52           If $mod starts with the '+' character the character will be removed
53           and the result returned without prepending $prefix.
54
55       hub_truth
56           This is an internal implementation detail, do not use it.
57
58       $hashref = parse_exit($?)
59           This parses the exit value as typically stored in $?.
60
61           Resulting hash:
62
63               {
64                   sig => ($? & 127), # Signal value if the exit was caused by a signal
65                   err => ($? >> 8),  # Actual exit code, if any.
66                   dmp => ($? & 128), # Was there a core dump?
67                   all => $?,         # Original exit value, unchanged
68               }
69
70       @list = process_includes(%PARAMS)
71           This method will build up a list of include dirs fit for @INC. The
72           returned list should contain only unique values, in proper order.
73
74           Params:
75
76           list => \@START
77               Paths to start the new list.
78
79               Optional.
80
81           ch_dir => $path
82               Prefix to prepend to all paths in the "list" param. No effect
83               without an initial list.
84
85           include_current => $bool
86               This will add all paths from @INC to the output, after the
87               initial list.  Note that '.', if in @INC will be moved to the
88               end of the final output.
89
90           clean => $bool
91               If included all paths except '.' will be cleaned using
92               "clean_path()".
93
94           include_dot => $bool
95               If true '.' will be appended to the end of the output.
96
97               Note even if this is set to false '.' may still be included if
98               it was in the initial list, or if it was in @INC and @INC was
99               included using the "include_current" parameter.
100
101   FOR DEALING WITH MODULE <-> FILE CONVERSION
102       These convert between module names like "Foo::Bar" and filenames like
103       "Foo/Bar.pm".
104
105       $file = mod2file($mod)
106       $mod = file2mod($file)
107
108   FOR READING/WRITING FILES
109       $fh = open_file($path, $mode)
110       $fh = open_file($path)
111           If no mode is provided '<' is assumed.
112
113           This will open the file at $path and return a filehandle.
114
115           An exception will be thrown if the file cannot be opened.
116
117           NOTE: This will automatically use IO::Uncompress::Bunzip2 or
118           IO::Uncompress::Gunzip to uncompress the file if it has a .bz2 or
119           .gz extension.
120
121       $text = read_file($file)
122           This will open the file at $path and return all its contents.
123
124           An exception will be thrown if the file cannot be opened.
125
126           NOTE: This will automatically use IO::Uncompress::Bunzip2 or
127           IO::Uncompress::Gunzip to uncompress the file if it has a .bz2 or
128           .gz extension.
129
130       $fh = maybe_open_file($path)
131       $fh = maybe_open_file($path, $mode)
132           If no mode is provided '<' is assumed.
133
134           This will open the file at $path and return a filehandle.
135
136           "undef" is returned if the file cannot be opened.
137
138           NOTE: This will automatically use IO::Uncompress::Bunzip2 or
139           IO::Uncompress::Gunzip to uncompress the file if it has a .bz2 or
140           .gz extension.
141
142       $text = maybe_read_file($path)
143           This will open the file at $path and return all its contents.
144
145           This will return "undef" if the file cannot be opened.
146
147           NOTE: This will automatically use IO::Uncompress::Bunzip2 or
148           IO::Uncompress::Gunzip to uncompress the file if it has a .bz2 or
149           .gz extension.
150
151       @content = write_file($path, @content)
152           Write content to the specified file. This will open the file with
153           mode '>', write the content, then close the file.
154
155           An exception will be thrown if any part fails.
156
157       @content = write_file_atomic($path, @content)
158           This will open a temporary file, write the content, close the file,
159           then rename the file to the desired $path. This is essentially an
160           atomic write in that $file will not exist until all content is
161           written, preventing other processes from doing a partial read while
162           @content is being written.
163

SOURCE

165       The source code repository for Test2-Harness can be found at
166       http://github.com/Test-More/Test2-Harness/.
167

MAINTAINERS

169       Chad Granum <exodist@cpan.org>
170

AUTHORS

172       Chad Granum <exodist@cpan.org>
173
175       Copyright 2020 Chad Granum <exodist7@gmail.com>.
176
177       This program is free software; you can redistribute it and/or modify it
178       under the same terms as Perl itself.
179
180       See http://dev.perl.org/licenses/
181
182
183
184perl v5.32.0                      2020-07-28           Test2::Harness::Util(3)
Impressum