File Coverage

blib/lib/vCard/Role/FileIO.pm
Criterion Covered Total %
statement 14 14 100.0
branch 3 6 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 22 25 88.0


line stmt bran cond sub pod time code
1             package vCard::Role::FileIO;
2             $vCard::Role::FileIO::VERSION = '3.08';
3 3     3   19320 use Moo::Role;
  3         5  
  3         15  
4 3     3   643 use Path::Tiny;
  3         3  
  3         474  
5              
6             requires qw/encoding_in encoding_out/;
7              
8             # PerlIO layers should look like ':encoding(UTF-8)'
9             # The ':encoding()' part does character set and encoding transformations.
10             # Without it you are just declaring the stream to be of a certain encoding.
11             # See PerlIO, PerlIO::encoding docs.
12              
13             sub _iomode_out {
14 2     2   3 my ($self) = @_;
15 2 50       10 return { binmode => ':raw' } if $self->encoding_out eq 'none';
16 2         12 return { binmode => ':raw:encoding(' . $self->encoding_out . ')' };
17             }
18              
19             sub _iomode_in {
20 3     3   5 my ($self) = @_;
21 3 50       13 return { binmode => ':raw' } if $self->encoding_in eq 'none';
22 3         21 return { binmode => ':raw:encoding(' . $self->encoding_in . ')' };
23             }
24              
25             # Filename can be a string, a Path::Tiny obj, or a Path::Class obj.
26             # Returns a Path::Tiny obj.
27             sub _path {
28 5     5   8 my ( $self, $filename ) = @_;
29 5 50       27 return ref $filename eq 'Path::Class::File' #
30             ? path("$filename")
31             : path($filename); # works for strings and Path::Tiny objects
32             }
33              
34             1;