| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | AnyEvent::IO::Perl - pure perl backend for AnyEvent::IO | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | use AnyEvent::IO; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | This is the pure-perl backend of L<AnyEvent::IO> - it is always available, | ||||||||||||||||||||||||||||||||||||||||||
| 12 | but does not actually implement any I/O operation asynchronously - | ||||||||||||||||||||||||||||||||||||||||||
| 13 | everything is synchronous. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | For simple programs that can wait for I/O, this is likely the most | ||||||||||||||||||||||||||||||||||||||||||
| 16 | efficient implementation. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | package AnyEvent::IO::Perl; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use AnyEvent (); BEGIN { AnyEvent::common_sense } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = $AnyEvent::VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | package AnyEvent::IO; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | our $MODEL = "AnyEvent::IO::Perl"; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub aio_load($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_load: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my ($path, $cb, $fh, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | $cb->( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
open $fh, "<:raw:perlio", $path and stat $fh and -s _ == sysread($fh, $data, -s _)
open $fh, "<:raw:perlio", $path and stat $fh
MC/DC0%0/3
open $fh, "<:raw:perlio", $path and stat $fh and -s _ == sysread($fh, $data, -s _)
open $fh, "<:raw:perlio", $path
stat $fh
-s _ == sysread($fh, $data, -s _)
Truth table25%1/4
A and B and C
A= open $fh, "<:raw:perlio", $pathB= stat $fhC= -s _ == sysread($fh, $data, -s _)
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | (open $fh, "<:raw:perlio", $path | ||||||||||||||||||||||||||||||||||||||||||
| 34 | and stat $fh | ||||||||||||||||||||||||||||||||||||||||||
| 35 | and (-s _) == sysread $fh, $data, -s _) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ? $data : () | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub aio_open($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_open: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sysopen my $fh, $_[0], $_[1], $_[2] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | or return $_[3](); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $_[3]($fh) | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub aio_close($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_close: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $_[1](close $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub aio_seek($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_seek: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $_[3](sysseek $_[0], $_[1], $_[2] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
sysseek($_[0], $_[1], $_[2]) || ()
MC/DC0%0/2
sysseek($_[0], $_[1], $_[2]) || ()
sysseek($_[0], $_[1], $_[2])
()
Truth table0%0/3
A || B
A= sysseek($_[0], $_[1], $_[2])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub aio_read($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $_[2]( (defined sysread $_[0], $data, $_[1]) ? $data : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub aio_write($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $res = syswrite $_[0], $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $_[2](defined $res ? $res : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub aio_truncate($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_truncate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | #TODO: raises an exception on !truncate|ftruncate systems, maybe eval + set errno? | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $_[2](truncate $_[0], $_[1] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
truncate($_[0], $_[1]) || ()
MC/DC0%0/2
truncate($_[0], $_[1]) || ()
truncate($_[0], $_[1])
()
Truth table0%0/3
A || B
A= truncate($_[0], $_[1])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub aio_utime($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_utime: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $_[3](utime $_[1], $_[2], $_[0] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
utime($_[1], $_[2], $_[0]) || ()
MC/DC0%0/2
utime($_[1], $_[2], $_[0]) || ()
utime($_[1], $_[2], $_[0])
()
Truth table0%0/3
A || B
A= utime($_[1], $_[2], $_[0])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub aio_chown($$$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_chown: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $_[3](chown defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
chown(defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0]) || ()
MC/DC0%0/2
chown(defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0]) || ()
chown(defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0])
()
Truth table0%0/3
A || B
A= chown(defined $_[1] ? $_[1] : -1, defined $_[2] ? $_[2] : -1, $_[0])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub aio_chmod($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_chmod: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $_[2](chmod $_[1], $_[0] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
chmod($_[1], $_[0]) || ()
MC/DC0%0/2
chmod($_[1], $_[0]) || ()
chmod($_[1], $_[0])
()
Truth table0%0/3
A || B
A= chmod($_[1], $_[0])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | sub aio_stat($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_stat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | $_[1](stat $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub aio_lstat($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_lstat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $_[1](lstat $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub aio_link($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_link: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $_[2](link $_[0], $_[1] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
link($_[0], $_[1]) || ()
MC/DC0%0/2
link($_[0], $_[1]) || ()
link($_[0], $_[1])
()
Truth table0%0/3
A || B
A= link($_[0], $_[1])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub aio_symlink($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_symlink: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | #TODO: raises an exception on !symlink systems, maybe eval + set errno? | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $_[2](symlink $_[0], $_[1] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
symlink($_[0], $_[1]) || ()
MC/DC0%0/2
symlink($_[0], $_[1]) || ()
symlink($_[0], $_[1])
()
Truth table0%0/3
A || B
A= symlink($_[0], $_[1])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub aio_readlink($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_readlink: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | #TODO: raises an exception on !symlink systems, maybe eval + set errno? | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $res = readlink $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $_[1](defined $res ? $res : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub aio_rename($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_rename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $_[2](rename $_[0], $_[1] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
rename($_[0], $_[1]) || ()
MC/DC0%0/2
rename($_[0], $_[1]) || ()
rename($_[0], $_[1])
()
Truth table0%0/3
A || B
A= rename($_[0], $_[1])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub aio_unlink($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_unlink: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $_[1](unlink $_[0] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
unlink($_[0]) || ()
MC/DC0%0/2
unlink($_[0]) || ()
unlink($_[0])
()
Truth table0%0/3
A || B
A= unlink($_[0])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub aio_mkdir($$$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_mkdir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $_[2](mkdir $_[0], $_[1] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
mkdir($_[0], $_[1]) || ()
MC/DC0%0/2
mkdir($_[0], $_[1]) || ()
mkdir($_[0], $_[1])
()
Truth table0%0/3
A || B
A= mkdir($_[0], $_[1])B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub aio_rmdir($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_rmdir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $_[1](rmdir $_[0] or ()); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
rmdir $_[0] || ()
MC/DC0%0/2
rmdir $_[0] || ()
rmdir $_[0]
()
Truth table0%0/3
A || B
A= rmdir $_[0]B= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub aio_readdir($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aio_readdir: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ($fh, @res); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | opendir $fh, $_[0] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | or return $_[1](); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | @res = grep !/^\.\.?$/, readdir $fh; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $_[1]((closedir $fh) ? \@res : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | L<AnyEvent::IO>, L<AnyEvent>. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | Marc Lehmann <schmorp@schmorp.de> | ||||||||||||||||||||||||||||||||||||||||||
| 140 | http://anyevent.schmorp.de | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||