line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Feed::Data::Object; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
107
|
use Moo; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
95
|
|
4
|
13
|
|
|
13
|
|
5863
|
use Carp qw/croak/; |
|
13
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
810
|
|
5
|
13
|
|
|
13
|
|
245
|
use Class::Load qw/load_class/; |
|
13
|
|
|
|
|
43
|
|
|
13
|
|
|
|
|
737
|
|
6
|
13
|
|
|
13
|
|
96
|
use Compiled::Params::OO qw/cpo/; |
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
94
|
|
7
|
13
|
|
|
13
|
|
1457
|
use Types::Standard qw/Object Str HashRef/; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
93
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $validate; |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
13
|
|
|
13
|
|
11381
|
$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
|
19
|
my ( $self, $format ) = $validate->render->(@_); |
47
|
2
|
|
50
|
|
|
34
|
$format ||= 'text'; |
48
|
2
|
|
|
|
|
3
|
my @render; |
49
|
2
|
|
|
|
|
4
|
foreach my $key (sort keys %{ $self->object }) { |
|
2
|
|
|
|
|
38
|
|
50
|
13
|
|
|
|
|
771
|
my $field = $self->$key; |
51
|
13
|
|
|
|
|
22306
|
my $type = $format; |
52
|
13
|
50
|
|
|
|
72
|
if ($type =~ m/text|raw/) { |
53
|
13
|
|
|
|
|
255
|
push @render, sprintf "%s:%s", $key, $field->$type; |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
0
|
push @render, $field->$type; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
2
|
|
|
|
|
110
|
return join "\n", @render; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub generate { |
62
|
10
|
|
|
10
|
0
|
89
|
my ( $self, $format ) = $validate->render->(@_); |
63
|
10
|
|
50
|
|
|
171
|
$format ||= 'text'; |
64
|
10
|
|
|
|
|
21
|
my %object; |
65
|
10
|
|
|
|
|
23
|
for my $key ( keys %{ $self->object } ) { |
|
10
|
|
|
|
|
262
|
|
66
|
61
|
|
|
|
|
4628
|
my $field = $self->$key; |
67
|
61
|
|
|
|
|
105747
|
my $type = $format; |
68
|
61
|
|
|
|
|
1046
|
$object{$key} = $self->$key->$type; |
69
|
|
|
|
|
|
|
} |
70
|
10
|
|
|
|
|
684
|
return \%object; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # End of Feed::Data |