Data/Parser.pm

filter: Statementstmt 35.4% 17 / 48 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod n/a totaltotal 23.3% 21 / 90 CC 17 SCAR 42.6
CC
17
Cov
21%
__ANON__
90.0
__ANON__
90.0
__ANON__
2.0
CRAP 70.7
↑ Summary Data/Parser/Base.pm »
1 package Feed::Data::Parser;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Class::Load qw/load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Types::Standard qw/Object ScalarRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 has 'stream' => (
10 is => 'ro',
11 isa => ScalarRef,
12 lazy => 1,
13 );
14  
15 has 'parse_tag' => (
16 is => 'ro',
17 isa => Str,
18 lazy => 1,
19 default => sub {
20 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=9 SCAR=45.0
21 0 my $content = $self->stream;
22 0 my $tag;
23 0 ▶ if ($$content =~ m/^([A-Za-z]+)\s*\:/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($$content =~ /^([A-Za-z]+)\s*\:/) { } 0 0 0
elsif ($$content =~ /^\s*\[/) { } 0 0 0
elsif ($$content =~ /^([A-Za-z]+,)/) { } 0 0 0
elsif ($$content =~ /---/) { } 0 0 0
24 0 $tag = 'text';
25 } elsif ($$content =~ m/^\s*\[/) {
26 0 $tag = 'json';
27 } elsif ($$content =~ m/^([A-Za-z]+,)/) {
28 0 $tag = 'csv';
29 } elsif ($$content =~ m/---/) {
30 0 $tag = 'yaml';
31 } else {
32 0 ▶ while ( $$content =~ /<(\S+)/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$content =~ /<(\S+)/gs) 0 0 0
33 0 (my $t = $1) =~ tr/a-zA-Z0-9:\-\?!//cd;
34 0 my $first = substr $t, 0, 1;
35 0 ▶ $tag = $t, last unless $first eq '?' || $first eq '!';
Branch: 1 branch
BranchTrueFalseTotal
unless $first eq "?" or $first eq "!" 0 0 0
Condition0%0/3
$first eq "?" or $first eq "!"
l!l&&r!l&&!r
000
MC/DC0%0/2
$first eq "?" or $first eq "!"
$first eq "?" $first eq "!"
Truth table0%0/3
A or B
A= $first eq "?"B= $first eq "!"
ABresult
1X1
011
000
36 }
37 }
38 0 ▶ croak 'Could not find the first XML element' unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 0 0
39 0 $tag =~ s/^,*://;
40 0 return $tag;
41 }
42 1 );
43  
44 has 'parser_type' => (
45 is => 'ro',
46 isa => Str,
47 lazy => 1,
48 default => sub {
49 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=9 SCAR=45.0
50 0 my $tag = $self->parse_tag;
51 0 ▶ return 'RSS' if $tag =~ /^(?:rss|rdf)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^(?:rss|rdf)$/i 0 0 0
52 0 ▶ return 'Atom' if $tag =~ /^feed/i;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^feed/i 0 0 0
53 0 ▶ return 'Meta' if $tag =~ /^html/i;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^html/i 0 0 0
54 0 ▶ return 'Text' if $tag =~ /^text/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^text/ 0 0 0
55 0 ▶ return 'JSON' if $tag =~ /^json/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^json/ 0 0 0
56 0 ▶ return 'CSV' if $tag =~ /^csv/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^csv/ 0 0 0
57 0 ▶ return 'Table' if $tag =~ /^table/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^table/ 0 0 0
58 0 ▶ return 'YAML' if $tag =~ /^yaml/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /^yaml/ 0 0 0
59 0 return croak "Could not find a parser";
60 }
61 1 );
62  
63 has 'parse' => (
64 is => 'ro',
65 isa => Object,
66 lazy => 1,
67 default => sub {
68 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 my $type = $self->parser_type;
70 0 my $class = "Feed::Data::Parser::" . $type;
71 0 load_class($class);
72 0 return $class->new(content_ref => $self->stream);
73 }
74 1 );
75  
76 1 1; # End of Feed::Data
↑ Summary Data/Parser/Base.pm »