| 1 | package Feed::Data::Parser::RSS; | ||
| 2 | |||
| 3 | use Moo; | ||
| 4 | extends 'Feed::Data::Parser::Base'; | ||
| 5 | use XML::RSS::LibXML; | ||
| 6 | use Ref::Util ':all'; | ||
| 7 | use Compiled::Params::OO qw/cpo/; | ||
| 8 | use Types::Standard qw/Object HashRef Str/; | ||
| 9 | |||
| 10 | our $validate; | ||
| 11 | BEGIN { | ||
| 12 | $validate = cpo( | ||
| 13 | get_value => [Object, HashRef, Str], | ||
| 14 | ); | ||
| 15 | } | ||
| 16 | |||
| 17 | has '+parser' => ( | ||
| 18 | default => sub { | ||
| 19 | my $self = shift; | ||
| 20 | return XML::RSS::LibXML->new->parse($self->content_ref); | ||
| 21 | }, | ||
| 22 | ); | ||
| 23 | |||
| 24 | sub get_value { | ||
| 25 | my ($self, $item, $action) = $validate->get_value->(@_); | ||
| 26 | |||
| 27 | my $value = $item->{$action}; | ||
| 28 | |||
| 29 | if ( is_scalarref(\$value) || is_arrayref($value) ){ | ||
| 30 | return $value; | ||
| 31 | } | ||
| 32 | elsif ( is_hashref($value) ){ | ||
| 33 | return $value->{encoded}; | ||
| 34 | } | ||
| 35 | |||
| 36 | return ''; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; # End of Feed::Data |