Data/Object.pm

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 2 totaltotal 41.7% 28 / 67 CC 6 SCAR 21.3
CC
6
Cov
42%
render
20.0
generate
12.0
__ANON__
2.0
CRAP 8.4
« Data/Parser/Base.pm ↑ Summary Data/Stream.pm »
1 package Feed::Data::Object;
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 1 ▶use Class::Load qw/load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Compiled::Params::OO qw/cpo/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Types::Standard qw/Object Str HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $validate;
10 BEGIN {
11 1 ▶ $validate = cpo(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 render => [Object, Str],
13 generate => [Object, Str],
14 );
15 }
16  
17 has 'object' => (
18 is => 'ro',
19 isa => HashRef,
20 lazy => 1,
21 0 ▶ default => sub { { } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 1 handles_via => 'Hash',
23 handles => {
24 object_keys => 'keys',
25 fields => 'get',
26 edit => 'set',
27 },
28 );
29  
30 1 my @fields = qw(title description image date author category permalink comment link content);
31 1 foreach my $field (@fields){
32 has $field => (
33 is => 'ro',
34 lazy => 1,
35 isa => Object,
36 default => sub {
37 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 my $class = 'Feed::Data::Object::' . ucfirst($field);
39 0 load_class($class);
40 0 return $class->new(raw => $self->object->{$field});
41 }
42 10 );
43 }
44  
45 sub render {
46 0 ▶ my ( $self, $format ) = $validate->render->(@_);
Subroutine render: not called CC=4 SCAR=30.0
Pod undocumented
47 0 ▶ $format ||= 'text';
Condition0%0/2
$format ||= "text"
l!l
00
MC/DC0%0/1
$format ||= "text"
$format
Truth table0%0/2
A
A= $format
Aresult
11
00
48 0 my @render;
49 0 foreach my $key (sort keys %{ $self->object }) {
50 0 my $field = $self->$key;
51 0 my $type = $format;
52 0 ▶ if ($type =~ m/text|raw/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /text|raw/) { } 0 0 0
53 0 push @render, sprintf "%s:%s", $key, $field->$type;
54 } else {
55 0 push @render, $field->$type;
56 }
57 }
58 0 return join "\n", @render;
59 }
60  
61 sub generate {
62 0 ▶ my ( $self, $format ) = $validate->render->(@_);
Subroutine generate: not called CC=3 SCAR=24.8
Pod undocumented
63 0 ▶ $format ||= 'text';
Condition0%0/2
$format ||= "text"
l!l
00
MC/DC0%0/1
$format ||= "text"
$format
Truth table0%0/2
A
A= $format
Aresult
11
00
64 0 my %object;
65 0 for my $key ( keys %{ $self->object } ) {
66 0 my $field = $self->$key;
67 0 my $type = $format;
68 0 $object{$key} = $self->$key->$type;
69 }
70 0 return \%object;
71 }
72  
73 1 1; # End of Feed::Data
« Data/Parser/Base.pm ↑ Summary Data/Stream.pm »