initial commit
[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 IO::File;
12 use Moose;
13 with 'Business::BatchPayment::Transport';
14
15 has 'input' => (
16   is => 'rw',
17   isa => 'Maybe[FileHandle|Str]',
18   default => sub {
19     warn "no input passed to file transport; using /dev/null";
20     '/dev/null'
21   },
22   #lazy => 1,
23 );
24
25 has 'output' => (
26   is => 'rw',
27   isa => 'Maybe[FileHandle|Str]',
28   default => sub {
29     warn "no output passed to file transport; using /dev/null";
30     '/dev/null'
31   },
32   #lazy => 1,
33 );
34
35 sub upload {
36   my $self = shift;
37   my $text = shift;
38   my $fh;
39   if ( ref $self->output ) {
40     $fh = $self->output;
41   } else {
42     $fh = IO::File->new();
43     $fh->open($self->output,'>')
44       or die "couldn't write to ".$self->output;
45   }
46   print $fh $text;
47 }
48
49 sub download {
50   my $self = shift;
51   my $fh;
52   if ( ref $self->input ) {
53     $fh = $self->input;
54   } else {
55     $fh = IO::File->new();
56     $fh->open($self->input,'<')
57       or die "couldn't read from ".$self->input;
58   }
59   local $/;
60   my $text = <$fh>;
61 }
62
63 1;