line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Feed::Data::Object; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
97
|
use Moo; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
105
|
|
4
|
13
|
|
|
13
|
|
5272
|
use Carp qw/croak/; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
687
|
|
5
|
13
|
|
|
13
|
|
218
|
use Class::Load qw/load_class/; |
|
13
|
|
|
|
|
36
|
|
|
13
|
|
|
|
|
766
|
|
6
|
13
|
|
|
13
|
|
89
|
use Compiled::Params::OO qw/cpo/; |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
106
|
|
7
|
13
|
|
|
13
|
|
1200
|
use Types::Standard qw/Object Str HashRef/; |
|
13
|
|
|
|
|
52
|
|
|
13
|
|
|
|
|
158
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $validate; |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
13
|
|
|
13
|
|
11334
|
$validate = cpo( |
12
|
|
|
|
|
|
|
render => [Object, Str], |
13
|
|
|
|
|
|
|
generate => [Object, Str], |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'object' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => HashRef, |
20
|
|
|
|
|
|
|
lazy => 1, |
21
|
|
|
|
|
|
|
default => sub { { } }, |
22
|
|
|
|
|
|
|
handles_via => 'Hash', |
23
|
|
|
|
|
|
|
handles => { |
24
|
|
|
|
|
|
|
object_keys => 'keys', |
25
|
|
|
|
|
|
|
fields => 'get', |
26
|
|
|
|
|
|
|
edit => 'set', |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @fields = qw(title description image date author category permalink comment link content); |
31
|
|
|
|
|
|
|
foreach my $field (@fields){ |
32
|
|
|
|
|
|
|
has $field => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
lazy => 1, |
35
|
|
|
|
|
|
|
isa => Object, |
36
|
|
|
|
|
|
|
default => sub { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
my $class = 'Feed::Data::Object::' . ucfirst($field); |
39
|
|
|
|
|
|
|
load_class($class); |
40
|
|
|
|
|
|
|
return $class->new(raw => $self->object->{$field}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub render { |
46
|
2
|
|
|
2
|
0
|
18
|
my ( $self, $format ) = $validate->render->(@_); |
47
|
2
|
|
50
|
|
|
35
|
$format ||= 'text'; |
48
|
2
|
|
|
|
|
4
|
my @render; |
49
|
2
|
|
|
|
|
4
|
foreach my $key (sort keys %{ $self->object }) { |
|
2
|
|
|
|
|
41
|
|
50
|
13
|
|
|
|
|
784
|
my $field = $self->$key; |
51
|
13
|
|
|
|
|
21778
|
my $type = $format; |
52
|
13
|
50
|
|
|
|
73
|
if ($type =~ m/text|raw/) { |
53
|
13
|
|
|
|
|
245
|
push @render, sprintf "%s:%s", $key, $field->$type; |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
0
|
push @render, $field->$type; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
111
|
return join "\n", @render; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub generate { |
62
|
10
|
|
|
10
|
0
|
79
|
my ( $self, $format ) = $validate->render->(@_); |
63
|
10
|
|
50
|
|
|
142
|
$format ||= 'text'; |
64
|
10
|
|
|
|
|
23
|
my %object; |
65
|
10
|
|
|
|
|
22
|
for my $key ( keys %{ $self->object } ) { |
|
10
|
|
|
|
|
191
|
|
66
|
61
|
|
|
|
|
4627
|
my $field = $self->$key; |
67
|
61
|
|
|
|
|
104056
|
my $type = $format; |
68
|
61
|
|
|
|
|
1053
|
$object{$key} = $self->$key->$type; |
69
|
|
|
|
|
|
|
} |
70
|
10
|
|
|
|
|
665
|
return \%object; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # End of Feed::Data |