| 1 | package NewsExtractor::CSSExtractor; | ||||||||||
| 2 | 1 | ▶ | use v5.18; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | extends 'NewsExtractor::TXExtractor'; | |||||||||
| 6 | 1 | ▶ | use Importer 'NewsExtractor::TextUtil' => qw( normalize_whitespace remove_control_characters ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Types::Standard qw( InstanceOf ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | has css_selector => ( | |||||||||
| 11 | required => 1, | ||||||||||
| 12 | is => 'ro', | ||||||||||
| 13 | isa => InstanceOf['NewsExtractor::CSSRuleSet'] | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub _take { | ||||||||
|
Subroutine
_take: not called CC=2 SCAR=17.9
| |||||||||||
| 17 | 0 | my ($self, $sel) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 0 | $self->dom->find("$sel style, $sel script")->map('remove'); | |||||||||
| 20 | 0 | my $txt = "". $self->dom->find( $sel )->map('all_text')->join("\n\n"); | |||||||||
| 21 | 0 | ▶ | return undef if $txt eq ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 0 | $txt = normalize_whitespace(remove_control_characters($txt)); | |||||||||
| 24 | 0 | $txt =~ s/\s+$//; | |||||||||
| 25 | 0 | $txt =~ s/^\s+//; | |||||||||
| 26 | 0 | $txt =~ s/\n\n+/\n\n/g; | |||||||||
| 27 | 0 | return $txt; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub headline { | ||||||||
|
Subroutine
headline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 31 | 0 | my ($self) = @_; | |||||||||
| 32 | 0 | ▶ | my $ret = $self->_take($self->css_selector->headline) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | $ret =~ s/\n/ /g; | |||||||||
| 34 | 0 | return normalize_whitespace($ret); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub dateline { | ||||||||
|
Subroutine
dateline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||
| 39 | 0 | ▶ | my $ret = $self->_take($self->css_selector->dateline) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | $ret =~ s/\n/ /g; | |||||||||
| 41 | 0 | return normalize_whitespace($ret); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub journalist { | ||||||||
|
Subroutine
journalist: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 45 | 0 | my ($self) = @_; | |||||||||
| 46 | 0 | ▶ | my $ret = $self->_take( $self->css_selector->journalist ) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $ret =~ s/\n/ /g; | |||||||||
| 48 | 0 | return normalize_whitespace($ret); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub content_text { | ||||||||
|
Subroutine
content_text: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my ($self) = @_; | |||||||||
| 53 | 0 | return $self->_take( $self->css_selector->content_text ); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | 1; | |||||||||