| 1 | # ABSTRACT: download novel /bbs thread | ||||||||||||
| 2 | package Novel::Robot; | ||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Novel::Robot::Parser; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use Novel::Robot::Packer; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | #use File::Copy; | ||||||||||||
| 10 | 3 | ▶ | use Encode::Locale; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 3 | ▶ | use Encode; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 3 | our $VERSION = 0.45; | |||||||||||
| 14 | |||||||||||||
| 15 | sub new { | ||||||||||||
| 16 | 2 | ▶ | my ( $self, %opt ) = @_; | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||
| 17 | 2 | ▶ | $opt{max_process_num} ||= 3; | ||||||||||
|
Condition50%1/2
$opt{"max_process_num"} ||= 3
MC/DC0%0/1
$opt{"max_process_num"} ||= 3
$opt{"max_process_num"}
Truth table50%1/2
A
A= $opt{"max_process_num"}
| |||||||||||||
| 18 | 2 | ▶ | $opt{type} ||= 'html'; | ||||||||||
|
Condition50%1/2
$opt{"type"} ||= "html"
MC/DC0%0/1
$opt{"type"} ||= "html"
$opt{"type"}
Truth table50%1/2
A
A= $opt{"type"}
| |||||||||||||
| 19 | |||||||||||||
| 20 | 2 | my $parser = Novel::Robot::Parser->new( %opt ); | |||||||||||
| 21 | 2 | my $packer = Novel::Robot::Packer->new( %opt ); | |||||||||||
| 22 | 2 | my $browser = $parser->{browser}; | |||||||||||
| 23 | 2 | bless { %opt, parser => $parser, packer => $packer, browser => $browser }, | |||||||||||
| 24 | __PACKAGE__; | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | sub set_parser { | ||||||||||||
| 28 | 0 | ▶ | my ( $self, $site ) = @_; | ||||||||||
|
Subroutine
set_parser: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 29 | 0 | $self->{site} = $self->{parser}->detect_site( $site ); | |||||||||||
| 30 | 0 | $self->{parser} = Novel::Robot::Parser->new( %$self ); | |||||||||||
| 31 | 0 | return $self; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | sub set_packer { | ||||||||||||
| 35 | 0 | ▶ | my ( $self, $type ) = @_; | ||||||||||
|
Subroutine
set_packer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 36 | 0 | $self->{type} = $type; | |||||||||||
| 37 | 0 | $self->{packer} = Novel::Robot::Packer->new( %$self ); | |||||||||||
| 38 | 0 | return $self; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | sub get_page { | ||||||||||||
| 42 | 0 | ▶ | my ( $self, $page_url, %o ) = @_; | ||||||||||
|
Subroutine
get_page: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 43 | |||||||||||||
| 44 | 0 | my $page_ref = $self->{parser}->get_page_ref( $page_url, %o ); | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | my $dst_f = $self->{packer}->main( $page_ref, \%o ); | |||||||||||
| 47 | 0 | my $dst_fname = decode(locale=>$dst_f); | |||||||||||
| 48 | 0 | ▶ | print encode(locale=>"info: $page_ref->{writer}-$page_ref->{book}-1\noutput: $dst_fname\nlast_item_num: 1\n") if ( $o{verbose} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | return wantarray ? ( $dst_f, $page_ref ) : $dst_f; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | sub get_novel { | ||||||||||||
| 54 | 0 | ▶ | my ( $self, $index_url, %o ) = @_; | ||||||||||
|
Subroutine
get_novel: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||
| 55 | |||||||||||||
| 56 | 0 | my $novel_ref = $self->{parser}->get_novel_ref( $index_url, %o ); | |||||||||||
| 57 | 0 | ▶ | return unless ( $novel_ref ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 0 | ▶ | return unless ( @{ $novel_ref->{item_list} } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 0 | ▶ | return unless ( grep { $_->{content} } @{ $novel_ref->{item_list} } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | |||||||||||||
| 61 | 0 | ▶ | while( ! $novel_ref->{item_list}[-1]{content}){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 0 | pop @{$novel_ref->{item_list}}; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | my $last_item_num = | ||||||||||||
| 66 | 0 | ▶ | scalar( @{ $novel_ref->{item_list} } ) > 0 | ||||||||||
|
Condition0%0/2
$novel_ref->{"item_num"} or scalar @{$novel_ref->{"item_list"};}
MC/DC0%0/1
$novel_ref->{"item_num"} or scalar @{$novel_ref->{"item_list"};}
$novel_ref->{"item_num"}
Truth table0%0/2
A
A= $novel_ref->{"item_num"}
| |||||||||||||
| 67 | ? $novel_ref->{item_list}[-1]{id} | ||||||||||||
| 68 | 0 | ▶ | : ( $novel_ref->{item_num} || scalar( @{ $novel_ref->{item_list} } ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | |||||||||||||
| 70 | 0 | my $dst_f = $self->{packer}->main( $novel_ref, \%o ); | |||||||||||
| 71 | 0 | my $dst_fname = decode(locale=>$dst_f); | |||||||||||
| 72 | 0 | ▶ | print encode(locale=>"info: $novel_ref->{writer}-$novel_ref->{book}-$last_item_num\noutput: $dst_fname\nlast_item_num: $last_item_num\n") if ( $o{verbose} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | return wantarray ? ( $dst_f, $novel_ref ) : $dst_f; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | } ## end sub get_novel | ||||||||||||
| 76 | |||||||||||||
| 77 | |||||||||||||
| 78 | sub split_index { | ||||||||||||
| 79 | 0 | ▶ | my $s = $_[-1]; | ||||||||||
|
Subroutine
split_index: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 80 | 0 | ▶ | return ( $s, $s ) if ( $s =~ /^\d+$/ ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 0 | ▶ | if ( $s =~ /^\d*-\d*$/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | my ( $min, $max ) = split '-', $s; | |||||||||||
| 83 | 0 | return ( $min, $max ); | |||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | return; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 3 | 1; | |||||||||||
| 89 | |||||||||||||