blib/lib/WWW/Google/Docs/Upload.pm

filter: Statementstmt 40.7% 11 / 27 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 2 / 4 Podpod 100% 1 / 1 totaltotal 29.7% 14 / 47 CC 7 SCAR 36.8
CC
7
Cov
28%
upload
56.0
__ANON__
2.0
BEGIN
1.0
CRAP 39.6
↑ Summary
1 package WWW::Google::Docs::Upload;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.02';
7  
8 2 has email => ( is => 'rw', required => 1 );
9 2 has passwd => ( is => 'rw', required => 1 );
10  
11 has mech => (
12 is => 'rw',
13 isa => 'WWW::Mechanize',
14 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 my $mech = WWW::Mechanize->new( stack_depth => 1 );
16 0 $mech->env_proxy;
17 0 $mech->agent_alias('Windows IE 6');
18 0 $mech->timeout(10);
19 0 $mech;
20 },
21 2 );
22  
23 0 ▶sub upload {
Subroutine upload: not called CC=7 SCAR=40.3
Pod documented
24 0 my ($self, $file, $option) = @_;
25  
26 0 ▶ confess q{required filename to upload} unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
27 0 ▶ confess qq{no such file "$file"} unless -e $file && -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file and -f _ 0 0 0
Condition0%0/3
-e $file and -f _
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and -f _
-e $file -f _
Truth table0%0/3
A and B
A= -e $fileB= -f _
ABresult
0X0
100
111
28  
29 0 my $mech = $self->mech;
30 0 $mech->get('http://docs.google.com/DocAction?action=updoc&hl=en');
31  
32 0 ▶ if ($mech->res->base =~ /ServiceLogin/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mech->res->base =~ /ServiceLogin/) 0 0 0
33 0 $mech->submit_form(
34 fields => {
35 Email => $self->email,
36 Passwd => $self->passwd,
37 },
38 );
39 0 $mech->follow_link( tag => 'meta' );
40 0 ▶ confess 'login failed' unless $mech->res->base->host eq 'docs.google.com';
Branch: 1 branch
BranchTrueFalseTotal
unless $mech->res->base->host eq "docs.google.com" 0 0 0
41 }
42  
43 $mech->submit_form(
44 fields => {
45 uploadedFile => $file,
46 0 ▶ $option->{name} ? (DocName => $option->{name}) : (),
Branch: 1 branch
BranchTrueFalseTotal
$option->{'name'} ? : 0 0 0
47 },
48 );
49  
50 0 $mech->res;
51 }
52  
53 =head1 NAME
54  
55 WWW::Google::Docs::Upload - Upload documents to Google Docs
56  
57 =head1 SYNOPSIS
58  
59 use WWW::Google::Docs::Upload;
60
61 my $docs = WWW::Google::Docs::Upload->new(
62 email => 'your email',
63 passwd => 'your password'
64 );
65 $docs->upload('/path/to/yourfile.doc');
66  
67 =head1 DESCRIPTION
68  
69 This module helps you to upload your local document files to Google Docs.
70  
71 =head1 METHODS
72  
73 =head2 upload($filename, \%option)
74  
75 Upload document file (named $filename) to Google Docs.
76  
77 \%option is hashref and allowed key is:
78  
79 =over 4
80  
81 =item name
82  
83 Filename what you want to call (if different than the filename)
84  
85 =back
86  
87 =head1 AUTHOR
88  
89 Daisuke Murase <typester@cpan.org>
90  
91 =head1 COPYRIGHT
92  
93 This program is free software; you can redistribute
94 it and/or modify it under the same terms as Perl itself.
95  
96 The full text of the license can be found in the
97 LICENSE file included with this module.
98  
99 =cut
100  
101 2 1;
↑ Summary