File: FileIO.pm

package info (click to toggle)
libtext-vcard-perl 3.06-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 352 kB
  • ctags: 110
  • sloc: perl: 1,535; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package vCard::Role::FileIO;
$vCard::Role::FileIO::VERSION = '3.06';
use Moo::Role;
use Path::Tiny;

requires qw/encoding_in encoding_out/;

# PerlIO layers should look like ':encoding(UTF-8)'
# The ':encoding()' part does character set and encoding transformations.
# Without it you are just declaring the stream to be of a certain encoding.
# See PerlIO, PerlIO::encoding docs.

sub _iomode_out {
    my ($self) = @_;
    return { binmode => ':raw' } if $self->encoding_out eq 'none';
    return { binmode => ':raw:encoding(' . $self->encoding_out . ')' };
}

sub _iomode_in {
    my ($self) = @_;
    return { binmode => ':raw' } if $self->encoding_in eq 'none';
    return { binmode => ':raw:encoding(' . $self->encoding_in . ')' };
}

# Filename can be a string, a Path::Tiny obj, or a Path::Class obj.
# Returns a Path::Tiny obj.
sub _path {
    my ( $self, $filename ) = @_;
    return ref $filename eq 'Path::Class::File'    #
        ? path("$filename")
        : path($filename);    # works for strings and Path::Tiny objects
}

1;