blib/lib/Zuzu/Module/IO.pm

filter: Statementstmt 50.3% 225 / 447 Branchbran 30.1% 41 / 136 Conditioncond 31.3% 16 / 51 MC/DCmcdc 13.7% 4 / 29 Subroutinesub 45.4% 40 / 88 Podpod 0.0% 0 / 1 totaltotal 43.3% 326 / 752 CC 95 SCAR 23.2
CC
95
Cov
44%
_glob_flags_from_options
42.0
__ANON__
42.0
__ANON__
30.0
CRAP 10.1
« lib/Zuzu/Tidy/CLI.pm ↑ Summary blib/lib/Zuzu/Value/Equality.pm »
1 package Zuzu::Module::IO;
2  
3 61 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 our $VERSION = '0.007002';
6  
7 61 ▶use Encode qw( decode_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 61 ▶use Errno qw( EEXIST );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 61 ▶use File::Glob qw( bsd_glob GLOB_NOCHECK GLOB_QUOTE GLOB_BRACE GLOB_TILDE GLOB_NOCASE );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 61 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 61 ▶use Path::Tiny qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 cwd
13 path
14 rootdir
15 tempdir
16 tempfile
17 61 );
18 61 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 61 ▶use Zuzu::Util::NativeHelpers qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 native_class
22 native_function
23 native_functions
24 native_object
25 perl_to_zuzu
26 zuzu_bool
27 zuzu_to_perl
28 61 );
29 61 ▶use Zuzu::Value::BinaryString;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 61 ▶use Zuzu::Value::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 61 ▶use Zuzu::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 ▶sub _bool {
Subroutine _bool: called CC=2 SCAR=7.2
34 2 my ( $value ) = @_;
35  
36 2 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 2 0 2
37 }
38  
39 5 ▶sub _raw_mode {
Subroutine _raw_mode: called CC=2 SCAR=7.2
40 5 my ( $value ) = @_;
41  
42 5 ▶ return zuzu_bool( $value, 0 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
zuzu_bool($value, 0) ? : 0 5 5
43 }
44  
45 23 ▶sub _to_path_tiny {
Subroutine _to_path_tiny: called CC=5 SCAR=22.7
46 23 my ( $obj ) = @_;
47  
48 23 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($obj) and $obj->isa("Zuzu::Value::Object") and exists $obj->slots->{"_path_tiny"}) 23 0 23
Condition33%2/6
builtin::blessed($obj) and $obj->isa("Zuzu::Value::Object") and exists $obj->slots->{"_path_tiny"}
!ll&&!rl&&r
0023
builtin::blessed($obj) and $obj->isa("Zuzu::Value::Object")
!ll&&!rl&&r
0023
MC/DC0%0/3
builtin::blessed($obj) and $obj->isa("Zuzu::Value::Object") and exists $obj->slots->{"_path_tiny"}
builtin::blessed($obj) $obj->isa("Zuzu::Value::Object") exists $obj->slots->{"_path_tiny"}
Truth table25%1/4
A and B and C
A= builtin::blessed($obj)B= $obj->isa("Zuzu::Value::Object")C= exists $obj->slots->{"_path_tiny"}
ABCresult
0XX0
10X0
1100
1111
49 blessed($obj)
50 and $obj->isa('Zuzu::Value::Object')
51 and exists $obj->slots->{_path_tiny}
52 ) {
53 23 return $obj->slots->{_path_tiny};
54 }
55  
56 0 ▶ return path( defined $obj ? "$obj" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $obj ? : 0 0 0
57 }
58  
59 9 ▶sub _has_named_temp_option {
Subroutine _has_named_temp_option: called CC=4 SCAR=19.7
60 9 my ( $args, $name ) = @_;
61  
62 9 ▶ for ( my $i = 0; $i < @{$args} - 1; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$args;} - 1) 0 9 9
63 0 ▶ next if ref $args->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if ref $args->[$i] 0 0 0
64 0 ▶ return 1 if uc( $args->[$i] ) eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if uc $args->[$i] eq $name 0 0 0
65 }
66  
67 9 return 0;
68 }
69  
70 1312 ▶sub _new_path_object {
Subroutine _new_path_object: called CC=2 SCAR=6.9
71 1312 my ( $class_obj, $path_obj, $demolish_hook ) = @_;
72  
73 1312 my $object = native_object(
74 class => $class_obj,
75 slots => {
76 _path_tiny => $path_obj,
77 _line_cursor => undef,
78 _line_done => 0,
79 _line_mode => undef,
80 },
81 const => {
82 _path_tiny => 1,
83 _line_cursor => 0,
84 _line_done => 0,
85 _line_mode => 0,
86 },
87 );
88 1312 ▶ $object->demolish_hook($demolish_hook)
Branch: 1 branch
BranchTrueFalseTotal
if ref $demolish_hook eq "CODE" 9 1303 1312
89 if ref($demolish_hook) eq 'CODE';
90  
91 1312 return $object;
92 }
93  
94 9 ▶sub _temp_path_cleanup {
Subroutine _temp_path_cleanup: called CC=1 SCAR=0.1
95 9 my ( $path_obj, $recursive ) = @_;
96  
97 3 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
98 3 local $@;
99 3 eval {
100 3 ▶ if ($recursive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recursive) { } 0 3 3
101 0 $path_obj->remove_tree({ safe => 0 });
102 }
103 else {
104 3 $path_obj->remove;
105 }
106 3 1;
107 };
108 3 return;
109 9 };
110 }
111  
112 0 ▶sub _new_path_array {
Subroutine _new_path_array: not called CC=1 SCAR=6.9
113 0 my ( $class_obj, $paths ) = @_;
114  
115 my @wrapped = map {
116 0 _new_path_object( $class_obj, $_ )
117 0 } @{ $paths };
118  
119 0 return perl_to_zuzu( \@wrapped );
120 }
121  
122 0 ▶sub _stat_to_dict {
Subroutine _stat_to_dict: not called CC=2 SCAR=17.9
123 0 my ( $st ) = @_;
124  
125 0 ▶ return undef if not defined $st;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $st 0 0 0
126  
127 0 my %fields = (
128 dev => $st->dev,
129 ino => $st->ino,
130 mode => $st->mode,
131 nlink => $st->nlink,
132 uid => $st->uid,
133 gid => $st->gid,
134 rdev => $st->rdev,
135 size => $st->size,
136 atime => $st->atime,
137 mtime => $st->mtime,
138 ctime => $st->ctime,
139 blksize => $st->blksize,
140 blocks => $st->blocks,
141 );
142  
143 0 return perl_to_zuzu( \%fields );
144 }
145  
146 2 ▶sub _call_callback {
Subroutine _call_callback: called CC=3 SCAR=12.0
147 2 my ( $runtime, $callback, $args ) = @_;
148  
149 2 ▶ return if not blessed($callback)
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function") 0 2 2
Condition33%1/3
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($callback) and $callback->isa("Zuzu::Value::Function")
builtin::blessed($callback) $callback->isa("Zuzu::Value::Function")
Truth table33%1/3
A and B
A= builtin::blessed($callback)B= $callback->isa("Zuzu::Value::Function")
ABresult
0X0
100
111
150 or not $callback->isa('Zuzu::Value::Function');
151  
152 2 $runtime->_call_function( $callback, $args, '<std/io>', 0 );
153  
154 2 return;
155 }
156  
157 0 ▶sub _decode_if_utf8 {
Subroutine _decode_if_utf8: not called CC=2 SCAR=17.9
158 0 my ( $line, $raw ) = @_;
159  
160 0 ▶ return $line if $raw;
Branch: 1 branch
BranchTrueFalseTotal
if $raw 0 0 0
161 0 return decode_utf8( $line, 1 );
162 }
163  
164 2 ▶sub _type_name {
Subroutine _type_name: called CC=4 SCAR=14.1
165 2 my ( $value ) = @_;
166  
167 2 ▶ return 'Null' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
168 2 ▶ return 'BinaryString'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 1 1 2
Condition66%2/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
101
MC/DC50%1/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
169 if blessed($value) and $value->isa('Zuzu::Value::BinaryString');
170 1 return 'String';
171 }
172  
173 3 ▶sub _assert_binary_string {
Subroutine _assert_binary_string: called CC=3 SCAR=11.0
174 3 my ( $value, $label ) = @_;
175  
176 3 ▶ return if blessed($value) and $value->isa('Zuzu::Value::BinaryString');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 2 1 3
Condition66%2/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
102
MC/DC50%1/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
177  
178 1 my $type = _type_name( $value );
179 1 die Zuzu::Error->new_runtime(
180 message => "TypeException: $label expects BinaryString, got $type",
181 file => '<std/io>',
182 line => 0,
183 );
184 }
185  
186 6 ▶sub _assert_text_string {
Subroutine _assert_text_string: called CC=3 SCAR=11.0
187 6 my ( $value, $label ) = @_;
188  
189 6 ▶ return if not blessed($value);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) 5 1 6
190 1 ▶ return if not $value->isa('Zuzu::Value::BinaryString');
Branch: 1 branch
BranchTrueFalseTotal
unless $value->isa("Zuzu::Value::BinaryString") 0 1 1
191  
192 1 my $type = _type_name( $value );
193 1 die Zuzu::Error->new_runtime(
194 message => "TypeException: $label expects String, got $type",
195 file => '<std/io>',
196 line => 0,
197 );
198 }
199  
200 2 ▶sub _async_task {
Subroutine _async_task: called CC=1 SCAR=0.0
201 2 my ( $runtime, $name, $work, $wrap ) = @_;
202  
203 2 my $worker = $runtime->_new_task(
204 name => "$name.worker",
205 start => 1,
206 schedule => 1,
207 thunk => $work,
208 );
209 return $runtime->_new_task(
210 name => $name,
211 schedule => 1,
212 2 ▶ thunk => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
213 2 my $value = $worker->await;
214 2 ▶ return defined $wrap ? $wrap->($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $wrap ? : 0 2 2
215 },
216 2 );
217 }
218  
219 19 ▶sub _warn_blocking_operation {
Subroutine _warn_blocking_operation: called CC=2 SCAR=7.1
220 19 my ( $runtime, $operation ) = @_;
221  
222 19 ▶ $runtime->_warn_blocking_operation($operation)
Branch: 1 branch
BranchTrueFalseTotal
if $runtime->can("_warn_blocking_operation") 19 0 19
223 if $runtime->can('_warn_blocking_operation');
224  
225 19 return;
226 }
227  
228 0 ▶sub _glob_flags_from_options {
Subroutine _glob_flags_from_options: not called CC=6 SCAR=37.4
229 0 my ( $options ) = @_;
230  
231 0 ▶ return GLOB_NOCHECK | GLOB_QUOTE if ref($options) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $options ne "HASH" 0 0 0
232  
233 0 my $flags = GLOB_QUOTE;
234 0 ▶ if ( zuzu_bool( $options->{nocheck}, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (zuzu_bool($options->{"nocheck"}, 1)) 0 0 0
235 0 $flags |= GLOB_NOCHECK;
236 }
237 0 ▶ if ( zuzu_bool( $options->{brace}, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (zuzu_bool($options->{"brace"}, 1)) 0 0 0
238 0 $flags |= GLOB_BRACE;
239 }
240 0 ▶ if ( zuzu_bool( $options->{tilde}, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (zuzu_bool($options->{"tilde"}, 1)) 0 0 0
241 0 $flags |= GLOB_TILDE;
242 }
243 0 ▶ if ( zuzu_bool( $options->{nocase}, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (zuzu_bool($options->{"nocase"}, 0)) 0 0 0
244 0 $flags |= GLOB_NOCASE;
245 }
246  
247 0 return $flags;
248 }
249  
250 0 ▶sub _normalize_join_parts {
Subroutine _normalize_join_parts: not called CC=4 SCAR=30.0
251 0 my ( $parts ) = @_;
252  
253 0 my @out;
254 0 ▶ if ( ref($parts) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parts eq 'ARRAY') { } 0 0 0
255 0 ▶ @out = map { defined $_ ? "$_" : '' } @{ $parts };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
256 }
257 else {
258 0 ▶ @out = ( defined $parts ? "$parts" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $parts ? : 0 0 0
259 }
260  
261 0 return @out;
262 }
263  
264 483 ▶sub IMPORT {
Subroutine IMPORT: called CC=9 SCAR=33.1
Pod undocumented
265 483 my ( $class, $runtime ) = @_;
266  
267 483 my $path_class = native_class(
268 name => 'Path',
269 );
270 483 my $path_iterator_class = native_class(
271 name => 'PathIterator',
272 );
273 483 my $stdin_class = native_class(
274 name => 'STDINHandle',
275 );
276 483 my $stdout_class = native_class(
277 name => 'STDOUTHandle',
278 );
279 483 my $stderr_class = native_class(
280 name => 'STDERRHandle',
281 );
282  
283 1301 ▶ $path_class->native_constructor( sub {
Subroutine __ANON__: called CC=5 SCAR=16.7
284 1301 my ( $rt, $klass, $positional, $named ) = @_;
285 1301 ▶ my $raw = @{ $positional // [] }
Branch: 1 branch
BranchTrueFalseTotal
exists $named->{'path'} ? : 2 0 2
Condition50%1/2
$positional // []
l!l
13010
MC/DC0%0/1
$positional // []
$positional
Truth table50%1/2
A
A= $positional
Aresult
11
00
286 ? $positional->[0]
287 1301 ▶ : exists $named->{path} ? $named->{path} : '';
Branch: 1 branch
BranchTrueFalseTotal
@{$positional // [];} ? : 1299 2 1301
288 1301 ▶ my $p = path( defined $raw ? "$raw" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $raw ? : 1301 0 1301
289  
290 1301 return _new_path_object( $klass, $p );
291 483 } );
292  
293 my $simple_path_methods = native_functions(
294 names => [
295 qw(
296 basename
297 canonpath
298 is_absolute
299 is_relative
300 is_rootdir
301 realpath
302 subsumes
303 volume
304 exists
305 is_file
306 is_dir
307 size
308 size_human
309 touch
310 touchpath
311 )
312 ],
313 7245 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.9
314 7245 my ( $name ) = @_;
315 3 ▶ return sub {
Subroutine __ANON__: called CC=8 SCAR=27.2
316 3 my ( $self, @args ) = @_;
317 3 my $p = _to_path_tiny( $self );
318 3 ▶ if ( $name eq 'subsumes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "subsumes") 0 3 3
319 0 ▶ my $other = @args ? _to_path_tiny( $args[0] ) : path('');
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
320 0 return _bool( $p->subsumes( $other ) );
321 }
322 3 ▶ if ( $name eq 'touch' or $name eq 'touchpath' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "touch" or $name eq "touchpath") 0 3 3
Condition33%1/3
$name eq "touch" or $name eq "touchpath"
l!l&&r!l&&!r
003
MC/DC0%0/2
$name eq "touch" or $name eq "touchpath"
$name eq "touch" $name eq "touchpath"
Truth table33%1/3
A or B
A= $name eq "touch"B= $name eq "touchpath"
ABresult
1X1
011
000
323 0 my $out = $p->$name();
324 0 return _new_path_object( $path_class, $out );
325 }
326 3 my $value = $p->$name();
327 3 ▶ if ( $name =~ /\A(?:is_absolute|is_relative|is_rootdir|exists|is_file|is_dir)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\A(?:is_absolute|is_relative|is_rootdir|exists|is_file|is_dir)\z/) 2 1 3
328 2 return _bool( $value );
329 }
330 1 ▶ if ( $name eq 'realpath' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "realpath") 0 1 1
331 0 ▶ return defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
332 ? _new_path_object( $path_class, $value )
333 : undef;
334 }
335  
336 1 return $value;
337 7245 };
338 },
339 483 );
340  
341 $path_class->methods->{$_} = $simple_path_methods->{$_}
342 483 for CORE::keys %{ $simple_path_methods };
343  
344 483 for my $name ( qw( absolute child parent sibling ) ) {
345 $path_class->methods->{$name} = native_function(
346 name => $name,
347 0 ▶ native => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
348 0 my ( $self, @args ) = @_;
349 0 my $p = _to_path_tiny( $self );
350 my @mapped = map {
351 0 ▶ if ( blessed($_) and $_->isa('Zuzu::Value::Object') and exists $_->slots->{_path_tiny} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_) and $_->isa('Zuzu::Value::Object') and exists $_->slots->{'_path_tiny'}) { } 0 0 0
Condition0%0/6
builtin::blessed($_) and $_->isa("Zuzu::Value::Object") and exists $_->slots->{"_path_tiny"}
!ll&&!rl&&r
000
builtin::blessed($_) and $_->isa("Zuzu::Value::Object")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($_) and $_->isa("Zuzu::Value::Object") and exists $_->slots->{"_path_tiny"}
builtin::blessed($_) $_->isa("Zuzu::Value::Object") exists $_->slots->{"_path_tiny"}
Truth table0%0/4
A and B and C
A= builtin::blessed($_)B= $_->isa("Zuzu::Value::Object")C= exists $_->slots->{"_path_tiny"}
ABCresult
0XX0
10X0
1100
1111
352 0 $_->slots->{_path_tiny};
353 }
354 else {
355 0 ▶ defined $_ ? "$_" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
356 }
357 } @args;
358 0 my $new = $p->$name( @mapped );
359 0 return _new_path_object( $path_class, $new );
360 },
361 1932 );
362 }
363  
364 $path_class->methods->{to_String} = native_function(
365 name => 'to_String',
366 2 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
367 2 my ( $self ) = @_;
368 2 my $p = _to_path_tiny( $self );
369 2 return $p->stringify;
370 },
371 483 );
372  
373 $path_class->methods->{copy} = native_function(
374 name => 'copy',
375 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
376 0 my ( $self, $to, @rest ) = @_;
377 0 my $p = _to_path_tiny( $self );
378 0 my $target = _to_path_tiny( $to );
379 0 my $out = $p->copy( $target, @rest );
380 0 return _new_path_object( $path_class, $out );
381 },
382 483 );
383  
384 483 for my $name ( qw( move remove mkdir remove_tree ) ) {
385 $path_class->methods->{$name} = native_function(
386 name => $name,
387 0 ▶ native => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
388 0 my ( $self, @args ) = @_;
389 0 my $p = _to_path_tiny( $self );
390 my @mapped = map {
391 0 ▶ if ( blessed($_) and $_->isa('Zuzu::Value::Object') and exists $_->slots->{_path_tiny} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_) and $_->isa('Zuzu::Value::Object') and exists $_->slots->{'_path_tiny'}) { } 0 0 0
Condition0%0/6
builtin::blessed($_) and $_->isa("Zuzu::Value::Object") and exists $_->slots->{"_path_tiny"}
!ll&&!rl&&r
000
builtin::blessed($_) and $_->isa("Zuzu::Value::Object")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($_) and $_->isa("Zuzu::Value::Object") and exists $_->slots->{"_path_tiny"}
builtin::blessed($_) $_->isa("Zuzu::Value::Object") exists $_->slots->{"_path_tiny"}
Truth table0%0/4
A and B and C
A= builtin::blessed($_)B= $_->isa("Zuzu::Value::Object")C= exists $_->slots->{"_path_tiny"}
ABCresult
0XX0
10X0
1100
1111
392 0 $_->slots->{_path_tiny};
393 }
394 else {
395 0 $_;
396 }
397 } @args;
398 0 return $p->$name( @mapped );
399 },
400 1932 );
401 }
402  
403 $path_class->methods->{mkdir_exclusive} = native_function(
404 name => 'mkdir_exclusive',
405 0 ▶ native => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
406 0 my ( $self ) = @_;
407 0 my $p = _to_path_tiny( $self );
408 0 ▶ if ( mkdir $p->stringify ) {
Branch: 1 branch
BranchTrueFalseTotal
if (mkdir $p->stringify) 0 0 0
409 0 return 1;
410 }
411 0 ▶ return 0 if $! == EEXIST;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 17 0 0 0
412 0 die "IOError: mkdir_exclusive failed for $p: $!";
413 },
414 483 );
415  
416 $path_class->methods->{chmod} = native_function(
417 name => 'chmod',
418 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
419 0 my ( $self, $mode ) = @_;
420 0 my $p = _to_path_tiny( $self );
421 0 return $p->chmod( $mode );
422 },
423 483 );
424  
425 483 for my $name ( qw( spew append ) ) {
426 $path_class->methods->{$name} = native_function(
427 name => $name,
428 3 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
429 3 my ( $self, @args ) = @_;
430 3 _warn_blocking_operation( $runtime, "std/io Path.$name" );
431 3 my $p = _to_path_tiny( $self );
432 3 my $label = "Path.$name";
433 3 _assert_binary_string( $args[0], $label );
434 2 my $bytes = $args[0]->bytes;
435 2 return $p->$name( $bytes );
436 },
437 966 );
438 }
439  
440 483 for my $name ( qw( spew_utf8 append_utf8 ) ) {
441 $path_class->methods->{$name} = native_function(
442 name => $name,
443 6 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
444 6 my ( $self, @args ) = @_;
445 6 _warn_blocking_operation( $runtime, "std/io Path.$name" );
446 6 my $p = _to_path_tiny( $self );
447 6 my $label = "Path.$name";
448 6 _assert_text_string( $args[0], $label );
449 5 return $p->$name( @args );
450 },
451 966 );
452 }
453  
454 $path_class->methods->{slurp} = native_function(
455 name => 'slurp',
456 2 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
457 2 my ( $self ) = @_;
458 2 _warn_blocking_operation( $runtime, 'std/io Path.slurp' );
459 2 my $p = _to_path_tiny( $self );
460 2 my $bytes = $p->slurp();
461 2 return Zuzu::Value::BinaryString->new( bytes => $bytes );
462 },
463 483 );
464  
465 $path_class->methods->{slurp_utf8} = native_function(
466 name => 'slurp_utf8',
467 3 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
468 3 my ( $self ) = @_;
469 3 _warn_blocking_operation( $runtime, 'std/io Path.slurp_utf8' );
470 3 my $p = _to_path_tiny( $self );
471 # Lax decode (like readline_utf8): valid UTF-8 sequences for
472 # noncharacters such as U+10FFFE must round-trip, matching
473 # zuzu-rust and zuzu-js; strict :encoding(UTF-8) refuses them.
474 3 return decode_utf8( $p->slurp_raw(), 1 );
475 },
476 483 );
477  
478 $path_class->methods->{slurp_async} = native_function(
479 name => 'slurp_async',
480 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
481 0 my ( $self ) = @_;
482 0 my $p = _to_path_tiny( $self );
483 return _async_task(
484 $runtime,
485 'path.slurp_async',
486 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
487 0 return $p->slurp();
488 },
489 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
490 0 my ( $bytes ) = @_;
491 0 return Zuzu::Value::BinaryString->new( bytes => $bytes );
492 },
493 0 );
494 },
495 483 );
496  
497 $path_class->methods->{slurp_utf8_async} = native_function(
498 name => 'slurp_utf8_async',
499 2 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
500 2 my ( $self ) = @_;
501 2 my $p = _to_path_tiny( $self );
502 return _async_task(
503 $runtime,
504 'path.slurp_utf8_async',
505 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
506 0 return decode_utf8( $p->slurp_raw(), 1 );
507 },
508 2 );
509 },
510 483 );
511  
512 $path_class->methods->{lines} = native_function(
513 name => 'lines',
514 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
515 0 my ( $self ) = @_;
516 0 _warn_blocking_operation( $runtime, 'std/io Path.lines' );
517 0 my $p = _to_path_tiny( $self );
518 0 my @lines = $p->lines();
519 my @wrapped = map {
520 0 Zuzu::Value::BinaryString->new( bytes => $_ );
521 } @lines;
522 0 return perl_to_zuzu( \@wrapped );
523 },
524 483 );
525  
526 $path_class->methods->{lines_utf8} = native_function(
527 name => 'lines_utf8',
528 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
529 0 my ( $self ) = @_;
530 0 _warn_blocking_operation( $runtime, 'std/io Path.lines_utf8' );
531 0 my $p = _to_path_tiny( $self );
532 0 my @lines = map { decode_utf8( $_, 1 ) } $p->lines( { binmode => ':raw' } );
533 0 return perl_to_zuzu( \@lines );
534 },
535 483 );
536  
537 $path_class->methods->{lines_async} = native_function(
538 name => 'lines_async',
539 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
540 0 my ( $self ) = @_;
541 0 my $p = _to_path_tiny( $self );
542 return _async_task(
543 $runtime,
544 'path.lines_async',
545 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
546 0 return [ $p->lines() ];
547 },
548 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
549 0 my ( $lines ) = @_;
550 my @wrapped = map {
551 0 Zuzu::Value::BinaryString->new( bytes => $_ );
552 0 ▶ } @{ $lines // [] };
Condition0%0/2
$lines // []
l!l
00
MC/DC0%0/1
$lines // []
$lines
Truth table0%0/2
A
A= $lines
Aresult
11
00
553 0 return perl_to_zuzu( \@wrapped );
554 },
555 0 );
556 },
557 483 );
558  
559 $path_class->methods->{lines_utf8_async} = native_function(
560 name => 'lines_utf8_async',
561 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
562 0 my ( $self ) = @_;
563 0 my $p = _to_path_tiny( $self );
564 return _async_task(
565 $runtime,
566 'path.lines_utf8_async',
567 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
568 0 return [ $p->lines_utf8() ];
569 },
570 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
571 0 my ( $lines ) = @_;
572 0 ▶ return perl_to_zuzu( $lines // [] );
Condition0%0/2
$lines // []
l!l
00
MC/DC0%0/1
$lines // []
$lines
Truth table0%0/2
A
A= $lines
Aresult
11
00
573 },
574 0 );
575 },
576 483 );
577  
578 483 for my $name ( qw( spew append ) ) {
579 $path_class->methods->{ $name . '_async' } = native_function(
580 name => $name . '_async',
581 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
582 0 my ( $self, @args ) = @_;
583 0 my $p = _to_path_tiny( $self );
584 0 my $label = 'Path.' . $name . '_async';
585 0 _assert_binary_string( $args[0], $label );
586 0 my $bytes = $args[0]->bytes;
587 return _async_task(
588 $runtime,
589 'path.' . $name . '_async',
590 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
591 0 $p->$name($bytes);
592 0 return $p->stringify;
593 },
594 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
595 0 my ( $out ) = @_;
596 0 return _new_path_object( $path_class, path($out) );
597 },
598 0 );
599 },
600 966 );
601 }
602  
603 483 for my $name ( qw( spew_utf8 append_utf8 ) ) {
604 $path_class->methods->{ $name . '_async' } = native_function(
605 name => $name . '_async',
606 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 0 my ( $self, @args ) = @_;
608 0 my $p = _to_path_tiny( $self );
609 0 my $label = 'Path.' . $name . '_async';
610 0 _assert_text_string( $args[0], $label );
611 0 my @text_args = @args;
612 return _async_task(
613 $runtime,
614 'path.' . $name . '_async',
615 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
616 0 $p->$name(@text_args);
617 0 return $p->stringify;
618 },
619 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
620 0 my ( $out ) = @_;
621 0 return _new_path_object( $path_class, path($out) );
622 },
623 0 );
624 },
625 966 );
626 }
627  
628 $path_class->methods->{stat} = native_function(
629 name => 'stat',
630 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
631 0 my ( $self ) = @_;
632 0 my $p = _to_path_tiny( $self );
633 0 return _stat_to_dict( $p->stat );
634 },
635 483 );
636  
637 $path_class->methods->{lstat} = native_function(
638 name => 'lstat',
639 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
640 0 my ( $self ) = @_;
641 0 my $p = _to_path_tiny( $self );
642 0 return _stat_to_dict( $p->lstat );
643 },
644 483 );
645  
646 483 for my $name ( qw( edit_lines edit_lines_utf8 ) ) {
647 $path_class->methods->{$name} = native_function(
648 name => $name,
649 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
650 0 my ( $self, $callback ) = @_;
651 0 _warn_blocking_operation( $runtime, "std/io Path.$name" );
652 0 my $p = _to_path_tiny( $self );
653 0 ▶ $p->$name( sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
654 0 my ( $line ) = @_;
655 0 my $out = $runtime->_call_function( $callback, [ $line ], '<std/io>', 0 );
656 0 ▶ return defined $out ? "$out" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $out ? : 0 0 0
657 0 } );
658 0 return $self;
659 },
660 966 );
661 }
662  
663 $path_class->methods->{each_line} = native_function(
664 name => 'each_line',
665 1 ▶ native => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
666 1 my ( $self, $callback, $raw_opt ) = @_;
667 1 _warn_blocking_operation( $runtime, 'std/io Path.each_line' );
668 1 my $raw = _raw_mode( $raw_opt );
669 1 my $p = _to_path_tiny( $self );
670 1 ▶ my $fh = $raw ? $p->openr_raw : $p->openr_utf8;
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 1 1
671 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 2 1 3
672 2 ▶ my $value = $raw
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 2 2
673 ? Zuzu::Value::BinaryString->new( bytes => $line )
674 : $line;
675 2 _call_callback( $runtime, $callback, [ $value ] );
676 }
677 1 close $fh;
678 1 return $self;
679 },
680 483 );
681  
682 $path_class->methods->{next_line} = native_function(
683 name => 'next_line',
684 4 ▶ native => sub {
Subroutine __ANON__: called CC=10 SCAR=23.8
685 4 my ( $self, $raw_opt ) = @_;
686 4 _warn_blocking_operation( $runtime, 'std/io Path.next_line' );
687 4 my $raw = _raw_mode( $raw_opt );
688 4 my $cursor = $self->slots->{_line_cursor};
689 4 my $mode = $self->slots->{_line_mode};
690 4 ▶ if ( defined $cursor and defined $mode and $mode != $raw ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cursor and defined $mode and $mode != $raw) 0 4 4
Condition66%4/6
defined $cursor and defined $mode and $mode != $raw
!ll&&!rl&&r
220
defined $cursor and defined $mode
!ll&&!rl&&r
202
MC/DC0%0/3
defined $cursor and defined $mode and $mode != $raw
defined $cursor defined $mode $mode != $raw
Truth table50%2/4
A and B and C
A= defined $cursorB= defined $modeC= $mode != $raw
ABCresult
0XX0
10X0
1100
1111
691 0 close $cursor;
692 0 $self->slots->{_line_cursor} = undef;
693 0 $self->slots->{_line_done} = 0;
694 0 $cursor = undef;
695 }
696 4 ▶ return undef if not defined $cursor and $self->slots->{_line_done};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $cursor and $self->slots->{"_line_done"} 1 3 4
Condition100%3/3
not defined $cursor and $self->slots->{"_line_done"}
!ll&&!rl&&r
211
MC/DC100%2/2
not defined $cursor and $self->slots->{"_line_done"}
not defined $cursor $self->slots->{"_line_done"}
Truth table100%3/3
not(A) and B
A= not defined $cursorB= $self->slots->{"_line_done"}
ABresult
0X0
100
111
697 3 ▶ if ( not defined $cursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cursor) 1 2 3
698 1 my $p = _to_path_tiny( $self );
699 1 ▶ $cursor = $raw ? $p->openr_raw : $p->openr_utf8;
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 1 1
700 1 $self->slots->{_line_cursor} = $cursor;
701 1 $self->slots->{_line_done} = 0;
702 1 $self->slots->{_line_mode} = $raw;
703 }
704 3 my $line = <$cursor>;
705 3 ▶ if ( defined $line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 2 1 3
706 2 ▶ return $raw
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 2 2
707 ? Zuzu::Value::BinaryString->new( bytes => $line )
708 : $line;
709 }
710 1 close $cursor;
711 1 $self->slots->{_line_cursor} = undef;
712 1 $self->slots->{_line_done} = 1;
713 1 return undef;
714 },
715 483 );
716  
717 $path_class->methods->{children} = native_function(
718 name => 'children',
719 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
720 0 my ( $self, @args ) = @_;
721 0 my $p = _to_path_tiny( $self );
722 0 my @kids = $p->children( @args );
723 0 return _new_path_array( $path_class, \@kids );
724 },
725 483 );
726  
727 $path_iterator_class->methods->{next} = native_function(
728 name => 'next',
729 0 ▶ native => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
730 0 my ( $self ) = @_;
731 0 my $iter = $self->slots->{_iter};
732 0 ▶ return undef if not defined $iter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $iter 0 0 0
733 0 my $next = $iter->();
734 0 ▶ return undef if not defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 0 0
735 0 return _new_path_object( $path_class, $next );
736 },
737 483 );
738  
739 $path_class->methods->{iterator} = native_function(
740 name => 'iterator',
741 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
742 0 my ( $self, @args ) = @_;
743 0 my $p = _to_path_tiny( $self );
744 0 my $iter = $p->iterator( @args );
745 0 return native_object(
746 class => $path_iterator_class,
747 slots => {
748 _iter => $iter,
749 },
750 const => {
751 _iter => 1,
752 },
753 );
754 },
755 483 );
756  
757 $path_class->methods->{visit} = native_function(
758 name => 'visit',
759 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
760 0 my ( $self, $callback, @args ) = @_;
761 0 my $p = _to_path_tiny( $self );
762 0 ▶ $p->visit( sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
763 0 my ( $entry ) = @_;
764 0 my $wrapped = _new_path_object( $path_class, $entry );
765 0 _call_callback( $runtime, $callback, [ $wrapped ] );
766 0 }, @args );
767 0 return $self;
768 },
769 483 );
770  
771 $path_class->static_methods->{cwd} = native_function(
772 name => 'cwd',
773 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
774 1 return _new_path_object( $path_class, cwd() );
775 },
776 483 );
777 $path_class->static_methods->{rootdir} = native_function(
778 name => 'rootdir',
779 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
780 1 return _new_path_object( $path_class, rootdir() );
781 },
782 483 );
783 $path_class->static_methods->{tempfile} = native_function(
784 name => 'tempfile',
785 9 ▶ native => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
786 9 my ( $self, @args ) = @_;
787 9 ▶ push @args, UNLINK => 0
Branch: 1 branch
BranchTrueFalseTotal
unless _has_named_temp_option(\@args, "UNLINK") 9 0 9
788 if not _has_named_temp_option( \@args, 'UNLINK' );
789 9 my $path = tempfile( @args );
790 9 return _new_path_object(
791 $path_class,
792 $path,
793 _temp_path_cleanup( $path, 0 ),
794 );
795 },
796 483 );
797 $path_class->static_methods->{tempdir} = native_function(
798 name => 'tempdir',
799 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
800 0 my ( $self, @args ) = @_;
801 0 ▶ push @args, CLEANUP => 0
Branch: 1 branch
BranchTrueFalseTotal
unless _has_named_temp_option(\@args, "CLEANUP") 0 0 0
802 if not _has_named_temp_option( \@args, 'CLEANUP' );
803 0 my $path = tempdir( @args );
804 0 return _new_path_object(
805 $path_class,
806 $path,
807 _temp_path_cleanup( $path, 1 ),
808 );
809 },
810 483 );
811 $path_class->static_methods->{glob} = native_function(
812 name => 'glob',
813 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
814 0 my ( $self, $pattern, $options ) = @_;
815 0 my $pattern_perl = zuzu_to_perl($pattern);
816 0 ▶ my $p = defined $pattern_perl ? "$pattern_perl" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $pattern_perl ? : 0 0 0
817 0 my $flags = _glob_flags_from_options( zuzu_to_perl($options) );
818 0 my @hits = bsd_glob( $p, $flags );
819 0 my @paths = map { path($_) } @hits;
820 0 return _new_path_array( $path_class, \@paths );
821 },
822 483 );
823 $path_class->static_methods->{join} = native_function(
824 name => 'join',
825 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
826 0 my ( $self, $parts ) = @_;
827 0 my @parts = _normalize_join_parts( zuzu_to_perl($parts) );
828 0 my $joined = path( @parts );
829 0 return _new_path_object( $path_class, $joined );
830 },
831 483 );
832 $path_class->static_methods->{split} = native_function(
833 name => 'split',
834 0 ▶ native => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
835 0 my ( $self, $raw_path ) = @_;
836 0 my $path_perl = zuzu_to_perl($raw_path);
837 0 ▶ my $input = defined $path_perl ? "$path_perl" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $path_perl ? : 0 0 0
838 0 my ( $vol, $dir, $base ) = File::Spec->splitpath($input);
839 0 my @parts = File::Spec->splitdir($dir);
840 0 ▶ push @parts, $base if $base ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $base ne "" 0 0 0
841 0 ▶ @parts = grep { defined $_ and $_ ne '' } @parts;
Condition0%0/3
defined $_ && $_ ne ''
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table0%0/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
842 0 ▶ unshift @parts, $vol if defined $vol and $vol ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $vol and $vol ne "" 0 0 0
Condition0%0/3
defined $vol and $vol ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vol and $vol ne ""
defined $vol $vol ne ""
Truth table0%0/3
A and B
A= defined $volB= $vol ne ""
ABresult
0X0
100
111
843 0 return perl_to_zuzu( \@parts );
844 },
845 483 );
846 $path_class->static_methods->{normalize} = native_function(
847 name => 'normalize',
848 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
849 0 my ( $self, $raw_path ) = @_;
850 0 my $path_perl = zuzu_to_perl($raw_path);
851 0 ▶ my $p = path( defined $path_perl ? "$path_perl" : '' );
Branch: 1 branch
BranchTrueFalseTotal
defined $path_perl ? : 0 0 0
852 0 my $canon = $p->canonpath;
853 0 return _new_path_object( $path_class, path($canon) );
854 },
855 483 );
856  
857 $stdin_class->methods->{next_line} = native_function(
858 name => 'next_line',
859 0 ▶ native => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
860 0 my ( $self, $raw_opt ) = @_;
861 0 my $raw = _raw_mode( $raw_opt );
862 0 my $line = <STDIN>;
863 0 ▶ return undef if not defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
864 0 ▶ return $raw
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 0 0
865 ? Zuzu::Value::BinaryString->new( bytes => $line )
866 : _decode_if_utf8( $line, $raw );
867 },
868 483 );
869  
870 $stdin_class->methods->{each_line} = native_function(
871 name => 'each_line',
872 0 ▶ native => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
873 0 my ( $self, $callback, $raw_opt ) = @_;
874 0 my $raw = _raw_mode( $raw_opt );
875 0 ▶ while ( my $line = <STDIN> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 0 0 0
876 0 ▶ my $value = $raw
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 0 0
877 ? Zuzu::Value::BinaryString->new( bytes => $line )
878 : _decode_if_utf8( $line, $raw );
879 0 _call_callback( $runtime, $callback, [ $value ] );
880 }
881 0 return undef;
882 },
883 483 );
884  
885 $stdout_class->methods->{print} = native_function(
886 name => 'print',
887 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
888 0 my ( $self, @args ) = @_;
889 0 ▶ print STDOUT join '', map { defined $_ ? "$_" : '' } @args;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
890 0 return undef;
891 },
892 483 );
893 $stdout_class->methods->{say} = native_function(
894 name => 'say',
895 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
896 0 my ( $self, @args ) = @_;
897 0 ▶ print STDOUT join( '', map { defined $_ ? "$_" : '' } @args ), "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
898 0 return undef;
899 },
900 483 );
901  
902 $stderr_class->methods->{print} = native_function(
903 name => 'print',
904 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
905 0 my ( $self, @args ) = @_;
906 0 ▶ print STDERR join '', map { defined $_ ? "$_" : '' } @args;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
907 0 return undef;
908 },
909 483 );
910 $stderr_class->methods->{say} = native_function(
911 name => 'say',
912 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
913 0 my ( $self, @args ) = @_;
914 0 ▶ print STDERR join( '', map { defined $_ ? "$_" : '' } @args ), "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
915 0 return undef;
916 },
917 483 );
918  
919 483 my $stdin_obj = native_object(
920 class => $stdin_class,
921 slots => {},
922 const => {},
923 );
924 483 my $stdout_obj = native_object(
925 class => $stdout_class,
926 slots => {},
927 const => {},
928 );
929 483 my $stderr_obj = native_object(
930 class => $stderr_class,
931 slots => {},
932 const => {},
933 );
934  
935 return {
936 483 Path => $path_class,
937 PathIterator => $path_iterator_class,
938 STDIN => $stdin_obj,
939 STDOUT => $stdout_obj,
940 STDERR => $stderr_obj,
941 };
942 }
943  
944 61 1;
945  
946 =pod
947  
948 =head1 NAME
949  
950 Zuzu::Module::IO - std/io bindings for ZuzuScript.
951  
952 =head1 DESCRIPTION
953  
954 Implements the C<std/io> module, exporting path and stream helpers.
955  
956 =head1 EXPORTS
957  
958 =head2 Path
959  
960 Filesystem path object backed by C<Path::Tiny>. Supports path
961 manipulation, metadata checks, file I/O, and traversal helpers.
962  
963 Notable methods include:
964  
965 =over
966  
967 =item * path transforms: C<absolute>, C<child>, C<parent>, C<sibling>
968  
969 =item * queries: C<exists>, C<is_file>, C<is_dir>, C<subsumes>
970  
971 =item * binary I/O: C<slurp>, C<spew>, C<append>, C<lines>
972  
973 =item * UTF-8 I/O: C<slurp_utf8>, C<spew_utf8>, C<append_utf8>, C<lines_utf8>
974  
975 =item * streaming: C<each_line>, C<next_line>
976  
977 =item * traversal: C<children>, C<iterator>, C<visit>
978  
979 =item * metadata: C<size>, C<size_human>, C<stat>, C<lstat>
980  
981 =item * directories: C<mkdir>, C<mkdir_exclusive>, C<remove_tree>
982  
983 =back
984  
985 Static helpers include C<cwd>, C<rootdir>, C<tempfile>, and C<tempdir>.
986  
987 =head2 PathIterator
988  
989 Iterator object returned by C<Path-E<gt>iterator>.
990  
991 Methods:
992  
993 =over
994  
995 =item * C<next()>
996  
997 =back
998  
999 =head2 STDIN
1000  
1001 Methods:
1002  
1003 =over
1004  
1005 =item * C<next_line(raw?)>
1006  
1007 =item * C<each_line(callback, raw?)>
1008  
1009 =back
1010  
1011 =head2 STDOUT and STDERR
1012  
1013 Methods:
1014  
1015 =over
1016  
1017 =item * C<print(...)>
1018  
1019 =item * C<say(...)>
1020  
1021 =back
1022  
1023 =head1 COPYRIGHT AND LICENCE
1024  
1025 B<< Zuzu::Module::IO >> is copyright Toby Inkster.
1026  
1027 It is free software; you may redistribute it and/or modify it under
1028 the terms of either the Artistic License 1.0 or the GNU General Public
1029 License version 2.
1030  
1031 =cut
« lib/Zuzu/Tidy/CLI.pm ↑ Summary blib/lib/Zuzu/Value/Equality.pm »