| 1 | package vCard::Role::FileIO; | ||||||||||
| 2 | 3 | $vCard::Role::FileIO::VERSION = '3.09'; | |||||||||
| 3 | 3 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | 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 | 2 | ▶ | sub _iomode_out { | ||||||||
|
Subroutine
_iomode_out: called CC=2 SCAR=7.1
| |||||||||||
| 14 | 2 | my ($self) = @_; | |||||||||
| 15 | 2 | ▶ | return { binmode => ':raw' } if $self->encoding_out eq 'none'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 2 | return { binmode => ':raw:encoding(' . $self->encoding_out . ')' }; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 3 | ▶ | sub _iomode_in { | ||||||||
|
Subroutine
_iomode_in: called CC=2 SCAR=7.1
| |||||||||||
| 20 | 3 | my ($self) = @_; | |||||||||
| 21 | 3 | ▶ | return { binmode => ':raw' } if $self->encoding_in eq 'none'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 3 | 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 | 5 | ▶ | sub _path { | ||||||||
|
Subroutine
_path: called CC=2 SCAR=7.2
| |||||||||||
| 28 | 5 | my ( $self, $filename ) = @_; | |||||||||
| 29 | 5 | ▶ | return ref $filename eq 'Path::Class::File' # | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | ? path("$filename") | ||||||||||
| 31 | : path($filename); # works for strings and Path::Tiny objects | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 3 | 1; | |||||||||