| 1 | # Copyrights 2011-2020 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||
| 5 | # This code is part of distribution IOMux. Meta-POD processed with OODoc | ||||||||||||||||||||||||||||
| 6 | # into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package IOMux::File::Write; | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use base 'IOMux::Handler::Write'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Log::Report 'iomux'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Fcntl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use File::Basename 'basename'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub init($) | ||||||||||||||||||||||||||||
| 24 | 4 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my $file = $args->{file} | ||||||||||||||||||||||||||||
| 27 | 4 | ▶ | or error __x"no file to open specified in {pkg}", pkg => __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | my $flags = $args->{modeflags}; | |||||||||||||||||||||||||||
| 30 | 4 | ▶ | my $mode = $args->{mode} || '>'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'mode'} || '>'
MC/DC100%1/1
$args->{'mode'} || '>'
$args->{'mode'}
Truth table100%2/2
A
A= $args->{'mode'}
| |||||||||||||||||||||||||||||
| 31 | 4 | ▶ | unless(ref $file || defined $flags) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $file or defined $flags
MC/DC0%0/2
ref $file or defined $flags
ref $file
defined $flags
Truth table33%1/3
A or B
A= ref $fileB= defined $flags
| |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | { if($mode eq '>>') { $args->{append} = 1 } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 33 | 3 | ▶ | elsif($mode eq '>') { $mode = '>>' if $args->{append} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | else | ||||||||||||||||||||||||||||
| 35 | 0 | { error __x"unknown file mode '{mode}' for {fn} in {pkg}" | |||||||||||||||||||||||||||
| 36 | , mode => $mode, fn => $file, pkg => __PACKAGE__; | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 4 | $flags = O_WRONLY|O_NONBLOCK; | |||||||||||||||||||||||||||
| 40 | 4 | ▶ | $flags |= O_CREAT unless exists $args->{create} && !$args->{create}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args->{"create"} and not $args->{"create"}
MC/DC0%0/2
exists $args->{"create"} and not $args->{"create"}
exists $args->{"create"}
not $args->{"create"}
Truth table33%1/3
A and not(B)
A= exists $args->{"create"}B= not $args->{"create"}
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | $flags |= O_APPEND if $args->{append}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | $flags |= O_EXCL if $args->{exclusive}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | my $fh; | |||||||||||||||||||||||||||
| 46 | 4 | ▶ | if(ref $file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | { $fh = $file; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else | ||||||||||||||||||||||||||||
| 50 | 4 | ▶ | { sysopen $fh, $file, $flags | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | or fault __x"cannot open file {fn} for {pkg}" | ||||||||||||||||||||||||||||
| 52 | , fn => $file, pkg => __PACKAGE__; | ||||||||||||||||||||||||||||
| 53 | 4 | $self->{IMFW_mode} = $flags; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 4 | $args->{name} = $mode.(basename $file); | |||||||||||||||||||||||||||
| 56 | 4 | $args->{fh} = $fh; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 4 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 59 | 4 | $self; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub open($$@) | ||||||||||||||||||||||||||||
| 64 | 2 | ▶ | { my ($class, $mode, $file, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
open: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 2 | $class->new(file => $file, mode => $mode, %args); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #------------------- | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub mode() {shift->{IMFW_mode}} | ||||||||||||||||||||||||||
|
Subroutine
mode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | 1; | |||||||||||||||||||||||||||