| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # file::raw Brik | ||
| 5 | # | ||
| 6 | package Metabrik::File::Raw; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::File::Write); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable read write) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | attributes => { | ||
| 19 | input => [ qw(file) ], | ||
| 20 | output => [ qw(file) ], | ||
| 21 | encoding => [ qw(utf8|ascii) ], # Inherited | ||
| 22 | }, | ||
| 23 | attributes_default => { | ||
| 24 | encoding => 'ascii', | ||
| 25 | }, | ||
| 26 | commands => { | ||
| 27 | read => [ qw(input) ], | ||
| 28 | write => [ qw($data|$data_ref|$data_list output) ], | ||
| 29 | }, | ||
| 30 | require_modules => { | ||
| 31 | 'Metabrik::File::Read' => [ ], | ||
| 32 | }, | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub read { | ||
| 37 | my $self = shift; | ||
| 38 | my ($input) = @_; | ||
| 39 | |||
| 40 | $input ||= $self->input; | ||
| 41 | $self->brik_help_run_undef_arg('read', $input) or return; | ||
| 42 | |||
| 43 | my $fr = Metabrik::File::Read->new_from_brik_init($self) or return; | ||
| 44 | $fr->input($input); | ||
| 45 | $fr->encoding('ascii'); | ||
| 46 | $fr->as_array(0); | ||
| 47 | $fr->strip_crlf(0); | ||
| 48 | |||
| 49 | $fr->open or return; | ||
| 50 | my $data = $fr->read or return; | ||
| 51 | $fr->close; | ||
| 52 | |||
| 53 | return $data; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub write { | ||
| 57 | my $self = shift; | ||
| 58 | my ($data, $output) = @_; | ||
| 59 | |||
| 60 | $output ||= $self->output; | ||
| 61 | $self->brik_help_run_undef_arg('write', $data) or return; | ||
| 62 | $self->brik_help_run_undef_arg('write', $output) or return; | ||
| 63 | |||
| 64 | $self->log->debug("write: data[$data]"); | ||
| 65 | |||
| 66 | $self->open($output) or return; | ||
| 67 | $self->SUPER::write($data) or return; | ||
| 68 | $self->close; | ||
| 69 | |||
| 70 | return 1; | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; | ||
| 74 | |||
| 75 | __END__ | ||