Scramble/Handler.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« Scramble/Entry.pm ↑ Summary
1 package WWW::Scramble::Handler;
2 0 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=2.6
3 use MooseX::AttributeHelpers;
4 use Carp;
5 use HTML::TreeBuilder::XPath;
6  
7 =head1 NAME
8  
9 WWW::Scramble::Handler
10  
11 =head1 SYNOPSIS
12  
13 Quick summary of what the module does.
14  
15 =cut
16  
17 has _xpath => (
18 is => 'ro',
19 isa => 'HTML::TreeBuilder::XPath',
20 default => sub { HTML::TreeBuilder::XPath->new }
21 );
22 has xtitle =>
23 ( is => 'rw', isa => 'Str', default => '//div[@id="ynwsart"]/*/h1' );
24 has xcontent =>
25 ( is => 'rw', isa => 'Str', default => '//div[@id="ynwsartcontent"]' );
26 has assets => (
27 metaclass => 'Collection::Hash',
28 is => 'rw',
29 isa => 'HashRef[Str]',
30 default => sub { {} },
31 provides => {
32 exists => 'exists_in_asset',
33 get => 'get_asset',
34 set => 'set_asset',
35 }
36 );
37  
38 =head1 FUNCTIONS
39  
40 =head2 parse
41  
42 =cut
43  
44 sub parse {
45 my ( $self, $raw ) = @_;
46 croak "Empty Content" unless $raw;
47 $self->_xpath->parse_content($raw) || croak "Parse error";
48 }
49  
50 after 'set_asset' => sub {
51 my ( $self ) = shift;
52 $self->xtitle($self->get_asset('xtitle')) if ( $self->exists_in_asset('xtitle') );
53 $self->xcontent($self->get_asset('xcontent')) if ( $self->exists_in_asset('xcontent') );
54 };
55  
56 =head2 get_title
57  
58 =cut
59  
60 sub get_title {
61 my ($self) = shift;
62 return $self->_xpath->findnodes($self->xtitle );
63 }
64  
65 =head2 get_content
66  
67 =cut
68  
69 sub get_content {
70 my ($self) = shift;
71 return $self->_xpath->findnodes($self->xcontent );
72 }
73  
74 =head2 get_field
75  
76 =cut
77  
78 sub get_field {
79 my ($self, $field, $node) = @_;
80 return $node->findnodes($self->get_asset($field))
81 if $node and 'HTML::Element' eq ref $node ;
82 return $self->_xpath->findnodes($self->get_asset($field));
83 }
84  
85 no Moose;
86 __PACKAGE__->meta->make_immutable;
87 1;
« Scramble/Entry.pm ↑ Summary