Data/Object.pm

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