| 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
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | confess qq{no such file "$file"} unless -e $file && -f _; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $file and -f _
MC/DC0%0/2
-e $file and -f _
-e $file
-f _
Truth table0%0/3
A and B
A= -e $fileB= -f _
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | $mech->submit_form( | ||||||||||||||||||||||||||||
| 44 | fields => { | ||||||||||||||||||||||||||||
| 45 | uploadedFile => $file, | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $option->{name} ? (DocName => $option->{name}) : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||