summaryrefslogtreecommitdiff
path: root/BatchPayment/Transport/File.pm
diff options
context:
space:
mode:
Diffstat (limited to 'BatchPayment/Transport/File.pm')
-rw-r--r--BatchPayment/Transport/File.pm63
1 files changed, 63 insertions, 0 deletions
diff --git a/BatchPayment/Transport/File.pm b/BatchPayment/Transport/File.pm
new file mode 100644
index 0000000..eaaba49
--- /dev/null
+++ b/BatchPayment/Transport/File.pm
@@ -0,0 +1,63 @@
+package Business::BatchPayment::Transport::File;
+
+=head2 File transport
+
+The simplest case. Takes two arguments, 'input' and 'output'. These can
+be open filehandles or strings naming files. If unspecified, they default
+to /dev/null.
+
+=cut
+
+use IO::File;
+use Moose;
+with 'Business::BatchPayment::Transport';
+
+has 'input' => (
+ is => 'rw',
+ isa => 'Maybe[FileHandle|Str]',
+ default => sub {
+ warn "no input passed to file transport; using /dev/null";
+ '/dev/null'
+ },
+ #lazy => 1,
+);
+
+has 'output' => (
+ is => 'rw',
+ isa => 'Maybe[FileHandle|Str]',
+ default => sub {
+ warn "no output passed to file transport; using /dev/null";
+ '/dev/null'
+ },
+ #lazy => 1,
+);
+
+sub upload {
+ my $self = shift;
+ my $text = shift;
+ my $fh;
+ if ( ref $self->output ) {
+ $fh = $self->output;
+ } else {
+ $fh = IO::File->new();
+ $fh->open($self->output,'>')
+ or die "couldn't write to ".$self->output;
+ }
+ print $fh $text;
+}
+
+sub download {
+ my $self = shift;
+ my $fh;
+ if ( ref $self->input ) {
+ $fh = $self->input;
+ } else {
+ $fh = IO::File->new();
+ $fh->open($self->input,'<')
+ or die "couldn't read from ".$self->input;
+ }
+ local $/;
+ my $text = <$fh>;
+}
+
+1;