line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Feed::Data::Object; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
12
|
|
|
12
|
|
86
|
use Moo; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
88
|
|
5
|
12
|
|
|
12
|
|
5109
|
use Carp qw/croak/; |
|
12
|
|
|
|
|
193
|
|
|
12
|
|
|
|
|
758
|
|
6
|
12
|
|
|
12
|
|
81
|
use Class::Load qw/load_class/; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
692
|
|
7
|
12
|
|
|
12
|
|
90
|
use Compiled::Params::OO qw/cpo/; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
88
|
|
8
|
12
|
|
|
12
|
|
1107
|
use Types::Standard qw/Object Str HashRef/; |
|
12
|
|
|
|
|
35
|
|
|
12
|
|
|
|
|
78
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $validate; |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
12
|
|
|
12
|
|
10212
|
$validate = cpo( |
13
|
|
|
|
|
|
|
render => [Object, Str], |
14
|
|
|
|
|
|
|
generate => [Object, Str], |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'object' => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => HashRef, |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
default => sub { { } }, |
23
|
|
|
|
|
|
|
handles_via => 'Hash', |
24
|
|
|
|
|
|
|
handles => { |
25
|
|
|
|
|
|
|
object_keys => 'keys', |
26
|
|
|
|
|
|
|
fields => 'get', |
27
|
|
|
|
|
|
|
edit => 'set', |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @fields = qw(title description image date author category permalink comment link content); |
32
|
|
|
|
|
|
|
foreach my $field (@fields){ |
33
|
|
|
|
|
|
|
has $field => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
isa => Object, |
37
|
|
|
|
|
|
|
default => sub { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
my $class = 'Feed::Data::Object::' . ucfirst($field); |
40
|
|
|
|
|
|
|
load_class($class); |
41
|
|
|
|
|
|
|
return $class->new(raw => $self->object->{$field}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub render { |
47
|
2
|
|
|
2
|
0
|
15
|
my ( $self, $format ) = $validate->render->(@_); |
48
|
2
|
|
50
|
|
|
31
|
$format ||= 'text'; |
49
|
2
|
|
|
|
|
5
|
my @render; |
50
|
2
|
|
|
|
|
4
|
foreach my $key (sort keys %{ $self->object }) { |
|
2
|
|
|
|
|
40
|
|
51
|
13
|
|
|
|
|
829
|
my $field = $self->$key; |
52
|
13
|
|
|
|
|
22222
|
my $type = $format; |
53
|
13
|
50
|
|
|
|
76
|
if ($type =~ m/text|raw/) { |
54
|
13
|
|
|
|
|
251
|
push @render, sprintf "%s:%s", $key, $field->$type; |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
0
|
push @render, $field->$type; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
112
|
return join "\n", @render; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub generate { |
63
|
8
|
|
|
8
|
0
|
65
|
my ( $self, $format ) = $validate->render->(@_); |
64
|
8
|
|
50
|
|
|
119
|
$format ||= 'text'; |
65
|
8
|
|
|
|
|
19
|
my %object; |
66
|
8
|
|
|
|
|
15
|
for my $key ( keys %{ $self->object } ) { |
|
8
|
|
|
|
|
160
|
|
67
|
48
|
|
|
|
|
3441
|
my $field = $self->$key; |
68
|
48
|
|
|
|
|
82624
|
my $type = $format; |
69
|
48
|
|
|
|
|
822
|
$object{$key} = $self->$key->$type; |
70
|
|
|
|
|
|
|
} |
71
|
8
|
|
|
|
|
713
|
return \%object; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; # End of Feed::Data |