| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$first eq "?" or $first eq "!"
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 "!"
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | croak 'Could not find the first XML element' unless $tag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return 'Atom' if $tag =~ /^feed/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return 'Meta' if $tag =~ /^html/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return 'Text' if $tag =~ /^text/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return 'JSON' if $tag =~ /^json/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return 'CSV' if $tag =~ /^csv/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return 'Table' if $tag =~ /^table/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return 'YAML' if $tag =~ /^yaml/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||