blib/lib/Slackware/Slackget/Network/Connection/DEBUG.pm

filter: Statementstmt 76.9% 60 / 78 Branchbran 55.5% 10 / 18 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 72.4% 84 / 116 CC 12 SCAR 18.1
CC
12
Cov
73%
__fetch_file
9.9
new
6.0
_validate_url
6.0
CRAP 6.1
↑ Summary
1 package Slackware::Slackget::Network::Connection::DEBUG;
2  
3 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
5 8 print STDOUT "[Slackware::Slackget::Network::Connection::DEBUG] driver compiled.\n";
6 }
7  
8 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 require Slackware::Slackget::Network::Connection;
11  
12 =head1 NAME
13  
14 Slackware::Slackget::Network::Connection::DEBUG - This class iimplements the debug:// protocol driver for Slackware::Slackget::Network::Connection
15  
16 =head1 VERSION
17  
18 Version 0.5
19  
20 =cut
21  
22 8 our $VERSION = '0.5';
23 8 print STDOUT "[Slackware::Slackget::Network::Connection::DEBUG] enable Slackware::Slackget::Network::Connection debug mode.\n";
24 8 $Slackware::Slackget::Network::Connection::DEBUG=1;
25  
26 =head1 SYNOPSIS
27  
28 This class implements the debug:// protocol driver for Slackware::Slackget::Network::Connection.
29  
30 You can't use this class without the Slackware::Slackget::Network::Connection one.
31  
32 This class was implemented for 2 main reasons :
33  
34 * To help coding and debuging new protocol drivers
35 * As a tutorial on how to code a new driver.
36  
37 You should always remember that this class do absolutly nothing !
38  
39 All downloads are fake ones as well as the
40  
41 =cut
42  
43 sub new
44 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
45 0 my ($class,$url,$config) = @_ ;
46 0 my $self = {};
47 0 ▶ return undef unless (is_url($self,$url));
Branch: 1 branch
BranchTrueFalseTotal
unless is_url($self, $url) 0 0 0
48 0 bless($self,$class);
49 0 $self->parse_url($url) ;
50 0 _debug_print("constructor called (it should not).");
51 0 return $self;
52 }
53  
54 30 ▶sub _debug_print {
Subroutine _debug_print: called CC=1 SCAR=0.0
55 30 print STDOUT "[Slackware::Slackget::Network::Connection::DEBUG] @_";
56 }
57  
58 =head1 CONSTRUCTOR
59  
60 =head2 new
61  
62 This class is not designed to be instanciate alone or used alone. You have to use the Slackware::Slackget::Network::Connection.
63  
64 =head1 FUNCTIONS
65  
66 =head2 __test_server
67  
68 This method act as if it test the rapidity of a repository. It return a random number between 10 and 90.
69  
70 Moreover it output a message on the standard output (STDOUT).
71  
72 my $time = $self->test_server() ;
73  
74 =cut
75  
76 1 ▶sub __test_server {
Subroutine __test_server: called CC=1 SCAR=0.0
77 1 my $self = shift ;
78 1 _debug_print("protocol : $self->{DATA}->{protocol}\n");
79 1 _debug_print("host : $self->{DATA}->{host}\n");
80 1 return (rand(90)+10);
81 }
82  
83 =head2 __get_file
84  
85 Return the following string :
86  
87 "This is a debug output from the Slackware::Slackget::Network::Connection::DEBUG network driver.\n"
88  
89 If you want it to return an error, please set an extra data called 'debug-want-error', like that :
90  
91 $connection->object_extra_data('debug-want-error', 1);
92 $connection->get_file('TEST.TXT');
93  
94 You can use this method like any other connection driver's one :
95  
96 my $file = $connection->get_file('PACKAGES.TXT') ;
97  
98 It output some informations (protocol, host, path and remote file) on the standard output (STDOUT).
99  
100 =cut
101  
102 2 ▶sub __get_file {
Subroutine __get_file: called CC=2 SCAR=6.9
103 2 my ($self,$remote_file) = @_ ;
104 2 _debug_print("[__get_file] protocol=".$self->protocol()."\n");
105 2 _debug_print("[__get_file] host=".$self->host()."\n");
106 2 _debug_print("[__get_file] path=".$self->path()."\n");
107 2 _debug_print("[__get_file] remote file downloaded=".$remote_file."\n");
108 2 $self->post_event('progress',$remote_file,1,100);
109 2 sleep 1;
110 2 $self->post_event('progress',$remote_file,33,100);
111 2 sleep 1;
112 2 $self->post_event('progress',$remote_file,66,100);
113 2 sleep 1;
114 2 $self->post_event('progress',$remote_file,99,100);
115 2 sleep 1;
116 2 $self->post_event('progress',$remote_file,100,100);
117 2 ▶ return undef if($self->object_extra_data('debug-want-error'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->object_extra_data("debug-want-error") 1 1 2
118 1 return "This is a debug output from the Slackware::Slackget::Network::Connection::DEBUG network driver.\n";
119 }
120  
121 =head2 __fetch_file
122  
123 Provide a
124  
125 This method return a Slackware::Slackget::Status object with the following object declaration :
126  
127 my $state = Slackware::Slackget::Status->new(codes => {
128 0 => "All goes well. Server said: $ret_code - ".status_message( $ret_code ),
129 1 => "Destination directory does not exist.\n",
130 2 => "Destination directory is not writable.\n",
131 3 => "Server error, you must choose the next host for this server. \nServer said: \nThis is a debug output from the Slackware::Slackget::Network::Connection::DEBUG network driver.",
132 });
133  
134 This method is also affected by the 'debug-want-error' extra data (if set with a true value it will generate a download error event).
135  
136 This method is also affected by the 'debug-want-success' extra data (if set with a true value, it will generate a download finished event)
137  
138 The default behavior is to randomize the generated state.
139  
140 =cut
141  
142 4 ▶sub __fetch_file {
Subroutine __fetch_file: called CC=9 SCAR=22.9
143 4 my ($self,$remote_file,$local_file) = @_ ;
144 4 ▶ $remote_file = $self->file unless(defined($remote_file));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remote_file 0 4 4
145 4 my $state = Slackware::Slackget::Status->new(codes => {
146 0 => "All goes well.",
147 1 => "Destination directory does not exist.",
148 2 => "Destination directory is not writable.",
149 3 => "Server error, you must choose the next host for this server. \nServer said: \nThis is a debug output from the Slackware::Slackget::Network::Connection::DEBUG network driver.",
150 4 => "Module error: unable to determine the path to save $remote_file",
151 });
152 4 ▶ unless(defined($local_file)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local_file) 2 2 4
153 2 ▶ if(defined($self->{DATA}->{download_directory}) && -e $self->{DATA}->{download_directory}){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'DATA'}{'download_directory'} and -e $self->{'DATA'}{'download_directory'}) { } 2 0 2
elsif (defined $self->{'DATA'}{'config'}) { } 0 0 0
Condition33%1/3
defined $self->{"DATA"}{"download_directory"} and -e $self->{"DATA"}{"download_directory"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"DATA"}{"download_directory"} and -e $self->{"DATA"}{"download_directory"}
defined $self->{"DATA"}{"download_directory"} -e $self->{"DATA"}{"download_directory"}
Truth table33%1/3
A and B
A= defined $self->{"DATA"}{"download_directory"}B= -e $self->{"DATA"}{"download_directory"}
ABresult
0X0
100
111
154 2 $remote_file=~ /([^\/]*)$/;
155 2 $local_file = $self->{DATA}->{download_directory}.'/'.$1 ;
156 }
157 elsif(defined($self->{DATA}->{config})){
158 0 $remote_file=~ /([^\/]*)$/;
159 0 $local_file = $self->{DATA}->{config}->{common}->{'update-directory'}.'/'.$1 ;
160 }
161 else{
162 0 warn "[Slackware::Slackget::Network::Connection::DEB$self->object_extra_data('debug-want-error')UG] unable to determine the path to save $remote_file.\n";
163 0 return $state->current(4);
164 0 return $state;
165 }
166 }
167 4 _debug_print("[__get_file] protocol=".$self->protocol()."\n");
168 4 _debug_print("[__get_file] host=".$self->host()."\n");
169 4 _debug_print("[__get_file] path=".$self->path()."\n");
170 4 _debug_print("[__get_file] remote file downloaded=".$remote_file."\n");
171 4 _debug_print("[__get_file] local file=".$local_file."\n");
172 4 $self->post_event('progress',$remote_file,1,100);
173 4 sleep 1;
174 4 $self->post_event('progress',$remote_file,33,100);
175 4 sleep 1;
176 4 $self->post_event('progress',$remote_file,66,100);
177 4 sleep 1;
178 4 $self->post_event('progress',$remote_file,99,100);
179 4 sleep 1;
180 4 $self->post_event('progress',$remote_file,100,100);
181 4 my $errno = int(rand(3));
182 4 ▶ $errno++ if($errno <= 0 && $self->object_extra_data('debug-want-error') );
Branch: 1 branch
BranchTrueFalseTotal
if $errno <= 0 and $self->object_extra_data("debug-want-error") 2 2 4
Condition100%3/3
$errno <= 0 and $self->object_extra_data("debug-want-error")
!ll&&!rl&&r
112
MC/DC100%2/2
$errno <= 0 and $self->object_extra_data("debug-want-error")
$errno <= 0 $self->object_extra_data("debug-want-error")
Truth table100%3/3
A and B
A= $errno <= 0B= $self->object_extra_data("debug-want-error")
ABresult
0X0
100
111
183 4 ▶ $errno = 0 if($self->object_extra_data('debug-want-success'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->object_extra_data("debug-want-success") 2 2 4
184 4 $state->current($errno);
185 4 return $state;
186 }
187  
188 0 ▶sub _validate_url {
Subroutine _validate_url: not called CC=2 SCAR=17.9
189 0 my ($self,$url)=@_ ;
190 0 ▶ if($url =~ m?^debug://.+?){
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ m?^debug://.+?) { } 0 0 0
191 0 _debug_print("validating the following url as a valid debug one : $url\n");
192 0 return 1 ;
193 }else{
194 0 _debug_print("could not validate the following url as a valid debug one : $url\n");
195 0 return 0;
196 }
197 }
198  
199 =head1 AUTHOR
200  
201 DUPUIS Arnaud, C<< <a.dupuis at infinityperl.org> >>
202  
203 =head1 BUGS
204  
205 Please report any bugs or feature requests to C<bug-slackware-slackget-network-connection-debug at rt.cpan.org>, or through
206 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget-Network-Connection-DEBUG>. I will be notified, and then you'll
207 automatically be notified of progress on your bug as I make changes.
208  
209  
210  
211  
212 =head1 SUPPORT
213  
214 You can find documentation for this module with the perldoc command.
215  
216 perldoc Slackware::Slackget::Network::Connection::DEBUG
217  
218  
219 You can also look for information at:
220  
221 =over 4
222  
223 =item * Infinity Perl website
224  
225 L<http://www.infinityperl.org>
226  
227 =item * RT: CPAN's request tracker
228  
229 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget-Network-Connection-DEBUG>
230  
231 =item * AnnoCPAN: Annotated CPAN documentation
232  
233 L<http://annocpan.org/dist/Slackware-Slackget-Network-Connection-DEBUG>
234  
235 =item * CPAN Ratings
236  
237 L<http://cpanratings.perl.org/d/Slackware-Slackget-Network-Connection-DEBUG>
238  
239 =item * Search CPAN
240  
241 L<http://search.cpan.org/dist/Slackware-Slackget-Network-Connection-DEBUG>
242  
243 =back
244  
245  
246 =head1 ACKNOWLEDGEMENTS
247  
248  
249 =head1 COPYRIGHT & LICENSE
250  
251 Copyright 2007 DUPUIS Arnaud, all rights reserved.
252  
253 This program is free software; you can redistribute it and/or modify it
254 under the same terms as Perl itself.
255  
256  
257 =cut
258  
259 8 1; # End of Slackware::Slackget::Network::Connection::DEBUG
↑ Summary