error callbacks, more structure for parse/format methods
[Business-BatchPayment.git] / BatchPayment / Transport / File.pm
1 package Business::BatchPayment::Transport::File;
2
3 =head2 File transport
4
5 The simplest case.  Takes two arguments, 'input' and 'output'.  These can 
6 be open filehandles or strings naming files.  If unspecified, they default 
7 to /dev/null.
8
9 =cut
10
11 use strict;
12 use Moose;
13 use IO::File;
14 with 'Business::BatchPayment::Transport';
15
16 has 'input' => (
17   is => 'rw',
18   isa => 'Maybe[FileHandle|Str]',
19   default => sub {
20     warn "no input passed to file transport; using /dev/null";
21     '/dev/null'
22   },
23   #lazy => 1,
24 );
25
26 has 'output' => (
27   is => 'rw',
28   isa => 'Maybe[FileHandle|Str]',
29   default => sub {
30     warn "no output passed to file transport; using /dev/null";
31     '/dev/null'
32   },
33   #lazy => 1,
34 );
35
36 sub upload {
37   my $self = shift;
38   my $text = shift;
39   my $fh;
40   if ( ref $self->output ) {
41     $fh = $self->output;
42   } else {
43     $fh = IO::File->new();
44     $fh->open($self->output,'>')
45       or die "couldn't write to ".$self->output;
46   }
47   print $fh $text;
48 }
49
50 sub download {
51   my $self = shift;
52   my $fh;
53   if ( ref $self->input ) {
54     $fh = $self->input;
55   } else {
56     $fh = IO::File->new();
57     $fh->open($self->input,'<')
58       or die "couldn't read from ".$self->input;
59   }
60   local $/;
61   my $text = <$fh>;
62 }
63
64 1;