Data/Parser.pm

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