| 1 | package App::perlrdf::FileSpec::OutputFile; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use autodie; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use utf8; | ||
| 8 | |||
| 9 | BEGIN { | ||
| 10 | $App::perlrdf::FileSpec::OutputFile::AUTHORITY = 'cpan:TOBYINK'; | ||
| 11 | $App::perlrdf::FileSpec::OutputFile::VERSION = '0.006'; | ||
| 12 | } | ||
| 13 | |||
| 14 | use Moose; | ||
| 15 | use LWP::UserAgent; | ||
| 16 | use Path::Class; | ||
| 17 | use namespace::clean; | ||
| 18 | |||
| 19 | extends 'App::perlrdf::FileSpec'; | ||
| 20 | |||
| 21 | use constant DEFAULT_STREAM => 'stdout:'; | ||
| 22 | |||
| 23 | has handle => ( | ||
| 24 | is => 'ro', | ||
| 25 | isa => 'Any', | ||
| 26 | lazy_build => 1, | ||
| 27 | ); | ||
| 28 | |||
| 29 | sub _build_handle | ||
| 30 | { | ||
| 31 | my $self = shift; | ||
| 32 | |||
| 33 | if (lc $self->uri->scheme eq 'file') | ||
| 34 | { | ||
| 35 | return Path::Class::File | ||
| 36 | -> new($self->uri->file) | ||
| 37 | -> openw | ||
| 38 | } | ||
| 39 | elsif (lc $self->uri->scheme eq 'stdout') | ||
| 40 | { | ||
| 41 | return \*STDOUT; | ||
| 42 | } | ||
| 43 | elsif (lc $self->uri->scheme eq 'stderr') | ||
| 44 | { | ||
| 45 | return \*STDERR; | ||
| 46 | } | ||
| 47 | else | ||
| 48 | { | ||
| 49 | die sprintf("TODO - '%s' URIs are not supported for output yet", $self->uri->scheme); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | 1; |