| 1 | 49 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 49 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package YAML::PP::Writer::File; | ||||||||||
| 4 | |||||||||||
| 5 | 49 | our $VERSION = 'v0.41.1'; # TRIAL VERSION | |||||||||
| 6 | |||||||||||
| 7 | 49 | ▶ | use Scalar::Util qw/ openhandle /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 49 | ▶ | use YAML::PP::Writer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 49 | our @ISA = qw/ YAML::PP::Writer /; | |||||||||
| 11 | |||||||||||
| 12 | 49 | ▶ | use Carp qw/ croak /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 6 | ▶ | sub _open_handle { | ||||||||
|
Subroutine
_open_handle: called CC=3 SCAR=11.0
| |||||||||||
| 15 | 6 | my ($self) = @_; | |||||||||
| 16 | 6 | ▶ | if (openhandle($self->{output})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | $self->{filehandle} = $self->{output}; | |||||||||
| 18 | 1 | return $self->{output}; | |||||||||
| 19 | } | ||||||||||
| 20 | open my $fh, '>:encoding(UTF-8)', $self->{output} | ||||||||||
| 21 | 5 | ▶ | or croak "Could not open '$self->{output}' for writing: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 4 | $self->{filehandle} = $fh; | |||||||||
| 23 | 4 | return $fh; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 30 | ▶ | sub write { | ||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 30 | my ($self, $line) = @_; | |||||||||
| 28 | 30 | my $fh = $self->{filehandle}; | |||||||||
| 29 | 30 | print $fh $line; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 6 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 6 | my ($self) = @_; | |||||||||
| 34 | 6 | my $fh = $self->_open_handle; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 5 | ▶ | sub finish { | ||||||||
|
Subroutine
finish: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 5 | my ($self) = @_; | |||||||||
| 39 | 5 | ▶ | if (openhandle($self->{output})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | # Original argument was a file handle, so the caller needs | ||||||||||
| 41 | # to close it | ||||||||||
| 42 | 1 | return; | |||||||||
| 43 | } | ||||||||||
| 44 | 4 | close $self->{filehandle}; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 49 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||