lib/WWW/Crawler/Mojo/Job.pm

filter: Statementstmt 70.4% 31 / 44 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 60.0% 3 / 5 totaltotal 65.6% 42 / 64 CC 4 SCAR 8.5
CC
4
Cov
67%
original_uri
6.0
add_props
3.2
child
2.0
CRAP 2.3
« lib/WWW/Crawler/Mojo/UserAgent.pm ↑ Summary
1 package WWW::Crawler::Mojo::Job;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 has 'literal_uri' => '';
8 7 has 'resolved_uri' => '';
9 7 has 'referrer' => '';
10 7 has 'depth' => 0;
11 1 ▶has 'additional_props' => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
12 0 ▶has 'redirect_history' => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
13 7 has 'method' => 'get';
14 7 has 'tx_params';
15  
16 sub clone {
17 1 ▶ my $self = shift;
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
18 1 my $new = __PACKAGE__->new(%$self);
19 1 $new->additional_props({%{$self->additional_props}});
20 1 return $new;
21 }
22  
23 sub child {
24 0 ▶ my $self = shift;
Subroutine child: not called CC=1 SCAR=6.9
Pod documented
25 my $child = __PACKAGE__->new(@_,
26 0 referrer => $self, depth => $self->{depth} + 1);
27 0 return $child;
28 }
29  
30 sub add_props {
31 1 ▶ my $self = shift;
Subroutine add_props: called CC=3 SCAR=11.7
Pod documented
32 1 ▶ my %hash = scalar @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 0 1 1
33 1 for (keys %hash) {
34 1 $self->additional_props->{$_} = $hash{$_};
35 }
36 }
37  
38 sub redirect {
39 0 ▶ my ($self, $last, @history) = @_;
Subroutine redirect: not called CC=1 SCAR=6.9
Pod documented
40 0 $self->resolved_uri($last);
41 0 $self->redirect_history(\@history);
42 }
43  
44 sub original_uri {
45 0 ▶ my $self = shift;
Subroutine original_uri: not called CC=2 SCAR=17.9
Pod undocumented
46 0 my @histry = @{$self->redirect_history};
47 0 ▶ return $self->resolved_uri unless (@histry);
Branch: 1 branch
BranchTrueFalseTotal
unless @histry 0 0 0
48 0 return $histry[$#histry];
49 }
50  
51 7 1;
52  
53 =head1 NAME
54  
55 WWW::Crawler::Mojo::Job - Single crawler job
56  
57 =head1 SYNOPSIS
58  
59 my $job = WWW::Crawler::Mojo::Job->new;
60  
61 =head1 DESCRIPTION
62  
63 This class represents a single crawler job.
64  
65 =head1 ATTRIBUTES
66  
67 =head2 literal_uri
68  
69 =head2 resolved_uri
70  
71 =head2 referrer
72  
73 =head2 depth
74  
75 =head2 additional_props
76  
77 Add propeties for job.
78  
79 $job->additional_props({key1 => $value1, key2 => $value2});
80  
81 =head2 redirect_history
82  
83 =head1 METHODS
84  
85 =head2 child
86  
87 Initiate a child job by parent job. The parent uri is set to child referrer.
88  
89 my $job1 = WWW::Crawler::Mojo::Job->new(resolved_uri => 'http://a/1');
90 my $job2 = $job1->child(resolved_uri => 'http://a/2');
91 say $job2->referrer # 'http://a/1'
92  
93 =head2 add_props
94  
95 =head2 redirect
96  
97 Replaces the resolved URI and history at once.
98  
99 my $job = WWW::Crawler::Mojo::Job->new;
100 $job->resolved_uri($url1);
101 $job->redirect($url2, $url3);
102 say $job->resolved_uri # $url2
103 say $job->redirect_history # [$url1, $url3]
104  
105 =head1 AUTHOR
106  
107 Sugama Keita, E<lt>sugama@jamadam.comE<gt>
108  
109 =head1 COPYRIGHT AND LICENSE
110  
111 Copyright (C) Sugama Keita.
112  
113 This program is free software; you can redistribute it and/or
114 modify it under the same terms as Perl itself.
115  
116 =cut
« lib/WWW/Crawler/Mojo/UserAgent.pm ↑ Summary