perlrdf/FileSpec/InputFile.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 76 CC 5 SCAR 16.7
CC
5
Cov
0%
_build_content
12.0
_build_handle
12.0
BEGIN
2.0
CRAP 5.3
1 package App::perlrdf::FileSpec::InputFile;
2  
3 use 5.010;
4 use autodie;
5 use strict;
6 use warnings;
7 use utf8;
8  
9 BEGIN {
10 $App::perlrdf::FileSpec::InputFile::AUTHORITY = 'cpan:TOBYINK';
11 $App::perlrdf::FileSpec::InputFile::VERSION = '0.006';
12 }
13  
14 use Moose;
15 use IO::Scalar;
16 use Path::Class;
17 use namespace::clean;
18  
19 extends 'App::perlrdf::FileSpec';
20  
21 use constant DEFAULT_STREAM => 'stdin:';
22  
23 has response => (
24 is => 'ro',
25 isa => 'HTTP::Response',
26 lazy_build => 1,
27 );
28  
29 has content => (
30 is => 'ro',
31 isa => 'Str',
32 lazy_build => 1,
33 );
34  
35 has handle => (
36 is => 'ro',
37 isa => 'Any',
38 lazy_build => 1,
39 );
40  
41 sub _build_response
42 {
43 LWP::UserAgent->new->get( shift->uri );
44 }
45  
46 sub _build_content
47 {
48 my $self = shift;
49
50 if (lc $self->uri->scheme eq 'file')
51 {
52 return scalar Path::Class::File
53 -> new($self->uri->file)
54 -> slurp
55 }
56 elsif (lc $self->uri->scheme eq 'stdin')
57 {
58 local $/ = <STDIN>;
59 return $/;
60 }
61 else
62 {
63 return $self->response->decoded_content;
64 }
65 }
66  
67 sub _build_handle
68 {
69 my $self = shift;
70
71 if (lc $self->uri->scheme eq 'file')
72 {
73 return Path::Class::File
74 -> new($self->uri->file)
75 -> open
76 }
77 elsif (lc $self->uri->scheme eq 'stdin')
78 {
79 return \*STDIN;
80 }
81 else
82 {
83 my $data = $self->content;
84 open my $fh, '<', \$data;
85 return $fh;
86 }
87 }
88  
89 1;