ManiacDownloader/_SegmentTask.pm

filter: Statementstmt 36.2% 21 / 58 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 4 / 14 Podpod n/a totaltotal 33.7% 25 / 74 CC 2 SCAR 8.2
CC
2
Cov
35%
_write_data
6.0
__ANON__
2.0
_serialize
2.0
CRAP 2.3
« ManiacDownloader.pm ↑ Summary ManiacDownloader/_BytesDownloaded.pm »
1 package App::ManiacDownloader::_SegmentTask;
2 2 $App::ManiacDownloader::_SegmentTask::VERSION = '0.0.13';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use MooX qw/late/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use List::Util qw/min/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has [ '_start', '_end' ] => ( is => 'rw', isa => 'Int', );
11 2 has '_fh' => ( is => 'rw', );
12 2 has 'is_active' => ( is => 'rw', isa => 'Bool', default => 1 );
13 has '_downloaded' => (
14 is => 'rw',
15 isa => 'App::ManiacDownloader::_BytesDownloaded',
16 0 ▶ default => sub { return App::ManiacDownloader::_BytesDownloaded->new; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 2 handles => ['_flush_and_report'],
18 );
19 2 has '_active_seq' => ( is => 'rw', isa => 'Int', default => 0 );
20  
21 2 has '_guard' => ( is => 'rw' );
22  
23 2 has '_count_checks_without_download' =>
24 ( is => 'rw', isa => 'Int', default => 0 );
25  
26 sub _serialize
27 0 ▶{
Subroutine _serialize: not called CC=1 SCAR=6.9
28 0 my ($self) = @_;
29  
30 return +{
31 0 _start => $self->_start,
32 _end => $self->_end,
33 is_active => $self->is_active,
34 };
35 }
36  
37 sub _deserialize
38 0 ▶{
Subroutine _deserialize: not called CC=1 SCAR=6.9
39 0 my ( $self, $record ) = @_;
40  
41 0 $self->_start( $record->{_start} );
42 0 $self->_end( $record->{_end} );
43 0 $self->is_active( $record->{is_active} );
44  
45 0 return;
46 }
47  
48 sub _write_data
49 0 ▶{
Subroutine _write_data: not called CC=2 SCAR=17.9
50 0 my ( $self, $data_ref ) = @_;
51  
52 0 my $written = syswrite( $self->_fh, $$data_ref );
53 0 ▶ if ( $written != length($$data_ref) )
Branch: 1 branch
BranchTrueFalseTotal
if ($written != length $$data_ref) 0 0 0
54 {
55 0 die "Written bytes mismatch.";
56 }
57  
58 0 $self->_downloaded->_add($written);
59  
60 0 my $init_start = $self->_start;
61 0 $self->_start( $init_start + $written );
62  
63 0 $self->_count_checks_without_download(0);
64  
65 return {
66 0 should_continue => scalar( $self->_start < $self->_end ),
67 num_written => ( min( $self->_start, $self->_end ) - $init_start ),
68 };
69 }
70  
71 sub _close
72 0 ▶{
Subroutine _close: not called CC=1 SCAR=6.9
73 0 my ($self) = @_;
74 0 close( $self->_fh );
75 0 $self->_fh( undef() );
76 0 $self->is_active(0);
77 0 $self->_guard('');
78  
79 0 return;
80 }
81  
82 sub _num_remaining
83 0 ▶{
Subroutine _num_remaining: not called CC=1 SCAR=6.9
84 0 my $self = shift;
85  
86 0 return $self->_end - $self->_start;
87 }
88  
89 sub _split_into
90 0 ▶{
Subroutine _split_into: not called CC=1 SCAR=6.9
91 0 my ( $self, $other ) = @_;
92  
93 0 $other->_start( ( $self->_start + $self->_end ) >> 1 );
94 0 $other->_end( $self->_end );
95 0 $self->_end( $other->_start );
96  
97 0 return;
98 }
99  
100 sub _increment_check_count
101 0 ▶{
Subroutine _increment_check_count: not called CC=1 SCAR=6.9
102 0 my ( $self, $max_checks ) = @_;
103  
104 0 $self->_count_checks_without_download(
105 $self->_count_checks_without_download() + 1 );
106  
107 0 return ( $self->_count_checks_without_download >= $max_checks );
108 }
109  
110 sub _get_next_active_seq
111 0 ▶{
Subroutine _get_next_active_seq: not called CC=1 SCAR=6.9
112 0 my ($self) = @_;
113  
114 0 return $self->_active_seq( $self->_active_seq() + 1 );
115 }
116  
117 sub _is_right_active_seq
118 0 ▶{
Subroutine _is_right_active_seq: not called CC=1 SCAR=6.9
119 0 my ( $self, $right_active_seq ) = @_;
120  
121 0 return ( $self->_active_seq() == $right_active_seq );
122 }
123  
124 2 1;
125  
126 __END__
« ManiacDownloader.pm ↑ Summary ManiacDownloader/_BytesDownloaded.pm »