/usr/share/perl5/MAB2/Writer/Handle.pm is in libcatmandu-mab2-perl 0.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | package MAB2::Writer::Handle;
our $VERSION = '0.13';
use strict;
use Moo::Role;
use Carp qw(croak);
use Encode qw(find_encoding);
use Scalar::Util qw(blessed openhandle);
has encoding => (
is => 'rw',
isa => sub {
find_encoding($_[0]) or croak "encoding \"$_[0]\" is not a valid encoding";
},
default => sub { 'UTF-8' },
);
has file => (
is => 'rw',
isa => sub {
croak 'expect file!' unless defined $_[0];
},
trigger => \&_set_fh,
);
has fh => (
is => 'rw',
isa => sub {
my $ishandle = eval { fileno( $_[0] ); };
croak 'expect filehandle or object with method print!'
unless !$@ and defined $ishandle
or ( blessed $_[0] && $_[0]->can('print') );
},
default => sub { \*STDOUT }
);
sub _set_fh {
my ($self) = @_;
my $encoding = $self->encoding;
open my $fh, ">:encoding($encoding)", $self->file
or croak 'could not open file!';
$self->fh($fh);
}
sub close_fh {
my ($self) = @_;
close $self->{fh};
}
sub write {
my ($self, @records) = @_;
foreach my $record (@records) {
$record = $record->{record} if ref $record eq 'HASH';
$self->_write_record($record);
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
MAB2::Writer::Handle - Utility class for common MAB2::Writer arguments and methods.
=head1 Arguments
=over
=item C<file>
Path to file.
=item C<fh>
Open filehandle.
=item C<encoding>
Set encoding.
=back
=head1 METHODS
=head2 _set_fh()
Open filehandle (with specified encoding) from file.
=head2 close_fh()
Close filehandle.
=head2 write()
Write record to filehandle.
=head1 AUTHOR
Johann Rolschewski <jorol@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Johann Rolschewski.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|