File Coverage

lib/WWW/RapidShare.pm
Criterion Covered Total %
statement 28 43 65.1
branch n/a
condition 1 3 33.3
subroutine 8 9 88.8
pod 2 2 100.0
total 39 57 68.4


line stmt bran cond sub pod time code
1             package WWW::RapidShare;
2 1     1   636 use strict; use warnings;
  1     1   1  
  1         41  
  1         7  
  1         1  
  1         40  
3 1     1   15 use base 'Class::Accessor';
  1         2  
  1         1075  
4              
5 1     1   2677 use version; our $VERSION = qv('0.3.1');
  1         2038  
  1         6  
6              
7 1     1   1309 use WWW::Mechanize;
  1         528051  
  1         44  
8 1     1   14 use File::Basename;
  1         2  
  1         122  
9 1     1   1041 use Data::Dumper;
  1         6642  
  1         350  
10              
11              
12             __PACKAGE__->mk_accessors(qw/
13             url
14             account_id
15             password
16             _mech
17             /);
18              
19             =pod
20              
21             =head1 NAME
22            
23             WWW::RapidShare - Download files from Rapidshare
24            
25            
26             =head1 VERSION
27            
28             This documentation refers to WWW::RapidShare version 0.3.1
29            
30            
31             =head1 NOTE
32              
33             Currently only works with rapidshare.com PREMIUM accounts.
34             More features coming soon!
35              
36             =head1 SYNOPSIS
37            
38             use WWW::RapidShare;
39              
40             my $rapid = WWW::RapidShare->new();
41              
42             $rapid->url('http://rapidshare.com/files/file.zip');
43             $rapid->account_id('xxxxxx');
44             $rapid->password('xxxxxx');
45            
46             # Download the file associated with the above URL.
47             # File will be saved in current directory.
48             $rapid->download_file();
49            
50            
51             =head1 SUBROUTINES/METHODS
52            
53             =cut
54              
55             =pod
56              
57             =head2 B
58              
59             =head3 Purpose
60              
61             Create a new WWW::RapidShare object
62              
63             =head3 Usage
64              
65             my $rapid = WWW::RapidShare->new();
66              
67             =head3 Parameters
68              
69             None
70              
71             =head3 Returns
72              
73             A WWW::RapidShare object
74              
75             =cut
76             sub new
77             {
78 1     1 1 742 my ($proto) = @_;
79              
80 1   33     9 my $class = ref $proto || $proto;
81 1         3 my $self = {};
82              
83 1         4 bless $self, $class;
84              
85             # Create our agent
86 1         8 my $mech = WWW::Mechanize->new();
87 1         19358 $self->_mech($mech);
88              
89 1         27 return $self;
90             }
91              
92             =pod
93              
94             =head2 B
95              
96             * url - The URL to download the file
97             * account_id - Your account ID
98             * password - your password
99              
100             =cut
101             =pod
102              
103             =head2 B
104              
105             =head3 Purpose
106              
107             Download the file associated with the URL
108              
109             =head3 Usage
110              
111             $rapid->download_file();
112              
113             =head3 Parameters
114              
115             None
116              
117             =head3 Returns
118              
119             None
120              
121             =head3 Comments
122              
123             This method will create a file in the current directory
124              
125             =cut
126             sub download_file
127             {
128 0     0 1   my $self = shift;
129              
130 0           $self->_mech->get($self->url);
131 0           $self->_mech->form_number(2);
132 0           $self->_mech->submit;
133              
134             # login
135 0           $self->_mech->form_with_fields(qw/accountid password/);
136 0           $self->_mech->field(accountid => $self->account_id);
137 0           $self->_mech->field(password => $self->password);
138 0           $self->_mech->submit();
139 0           $self->_mech->click_button(name => 'dl.start');
140              
141 0           my $ah_form = pop @{ $self->_mech->forms };
  0            
142              
143 0           my $file_name = basename($ah_form->action);
144              
145 0           print "Fetching " . $ah_form->action . " ...\n";
146 0           print "Saving file as $file_name\n";
147 0           $self->_mech->get( $ah_form->action, ":content_file" => $file_name );
148             }
149              
150             1;
151              
152             =head1 DEPENDENCIES
153            
154             =over 4
155              
156             =item * Class::Accessor
157              
158             =item * WWW::Mechanize
159              
160             =back
161              
162             =head1 AUTHOR
163            
164             Rohan Almeida
165            
166            
167             =head1 LICENCE AND COPYRIGHT
168            
169             Copyright (c) 2008 Rohan Almeida . All rights
170             reserved.
171              
172             This module is free software; you can redistribute it and/or
173             modify it under the same terms as Perl itself.
174              
175             This program is distributed in the hope that it will be useful,
176             but WITHOUT ANY WARRANTY; without even the implied warranty of
177             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
178