« NewsExtractor/SiteSpecificExtractor/www_hkcnews_com.pm
↑ Summary
NewsExtractor/SiteSpecificExtractor/yimedia_com_tw.pm »
| 1 | package NewsExtractor::JSONLDExtractor; | ||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 1 | extends 'NewsExtractor::TXExtractor'; | |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::Transaction::HTTP; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 1 | ▶ | use Types::Standard qw( InstanceOf HashRef ArrayRef ); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::JSON qw(from_json); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 1 | ▶ | use Importer 'NewsExtractor::TextUtil' => qw(u remove_control_characters); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 1 | has tx => ( | |||||||||||||||||||||||
| 11 | required => 1, is => 'ro', | ||||||||||||||||||||||||
| 12 | isa => InstanceOf['Mojo::Transaction::HTTP'] ); | ||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | 1 | has schema_ld => ( | |||||||||||||||||||||||
| 15 | required => 0, | ||||||||||||||||||||||||
| 16 | is => 'lazy', | ||||||||||||||||||||||||
| 17 | isa => HashRef, | ||||||||||||||||||||||||
| 18 | builder => 1, | ||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _build_schema_ld { | ||||||||||||||||||||||
|
Subroutine
_build_schema_ld: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||
| 22 | 0 | my ($self) = @_; | |||||||||||||||||||||||
| 23 | 0 | ▶ | my $el = $self->dom->at('script[type="application/ld+json"]') or return {}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 24 | 0 | my $x = from_json( $el->text ); | |||||||||||||||||||||||
| 25 | 0 | ▶ | if (HashRef->check($x)) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 26 | 0 | return $x; | |||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||
| 28 | 0 | ▶ | if (ArrayRef->check($x)) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 29 | 0 | return $x->[0]; | |||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||
| 31 | 0 | return {}; | |||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||
| 34 | 0 | ▶ | sub journalist { | ||||||||||||||||||||||
|
Subroutine
journalist: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 35 | 0 | my ($self) = @_; | |||||||||||||||||||||||
| 36 | 0 | return remove_control_characters(u($self->schema_ld->{author}{name})); | |||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||
| 39 | 0 | ▶ | sub headline { | ||||||||||||||||||||||
|
Subroutine
headline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 40 | 0 | my ($self) = @_; | |||||||||||||||||||||||
| 41 | 0 | return remove_control_characters(u($self->schema_ld->{headline})); | |||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||
| 44 | 0 | ▶ | sub dateline { | ||||||||||||||||||||||
|
Subroutine
dateline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 45 | 0 | my ($self) = @_; | |||||||||||||||||||||||
| 46 | 0 | return remove_control_characters(u($self->schema_ld->{datePublished})); | |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | 0 | ▶ | sub content_text { | ||||||||||||||||||||||
|
Subroutine
content_text: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||||||||||||||
| 51 | 0 | ▶ | my $text = $self->schema_ld->{articleBody} // $self->schema_ld->{description} // ''; | ||||||||||||||||||||||
|
Condition0%0/5
($self->schema_ld->{"articleBody"} // $self->schema_ld->{"description"}) // ""
$self->schema_ld->{"articleBody"} // $self->schema_ld->{"description"}
MC/DC0%0/2
($self->schema_ld->{"articleBody"} // $self->schema_ld->{"description"}) // ""
$self->schema_ld->{"articleBody"}
$self->schema_ld->{"description"}
Truth table0%0/3
A // B
A= $self->schema_ld->{"articleBody"}B= $self->schema_ld->{"description"}
| |||||||||||||||||||||||||
| 52 | 0 | return remove_control_characters(u($text)); | |||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | 1 | 1; | |||||||||||||||||||||||