public
Description: upload documents to google docs
Clone URL: git://github.com/typester/www-google-docs-upload.git
Search Repo:
commit  9ff95ec44fc7dcca029be5996c27d49374b10496
tree    0fe06cf972db10331224a4249df8525a48947931
parent  331b7a96f30b370b4de6edc90fd4aee7fd4b3d81
www-google-docs-upload / example / gdoc-upload.pl
100755 97 lines (69 sloc) 1.797 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env perl
 
use strict;
use warnings;
 
use Pod::Usage;
use Getopt::Long;
 
use FindBin;
use File::Spec;
use File::HomeDir;
use File::Temp ();
use lib File::Spec->catfile($FindBin::Bin, qw/.. lib/);
 
use YAML;
use ExtUtils::MakeMaker ();
use WWW::Google::Docs::Upload;
 
our $conf = File::Spec->catfile( File::HomeDir->my_home, '.gdoc_upload' );
our %config;
our $changed;
 
main();
 
END {
    save_config() if $changed;
}
 
sub prompt {
    my $value = ExtUtils::MakeMaker::prompt($_[0]);
    $changed++;
    $value;
}
 
sub main {
    GetOptions(
        \my %option,
        qw/help name=s/
    );
    pod2usage(0) if $option{help};
 
    setup_config();
 
    my ($filename, $fh);
    $filename = $ARGV[0];
 
    if (!$filename and my $stdin = do { local $/; <STDIN> }) {
        my ($suffix) = ($option{name} || '') =~ /(\.?[^.]+)$/;
        $fh = File::Temp->new( $suffix ? (SUFFIX => $suffix) : () );
        print $fh $stdin;
        $fh->close;
 
        $filename = $fh->filename;
    }
 
    pod2usage(1) unless $filename;
 
    my $gdoc = WWW::Google::Docs::Upload->new(
        email => $config{email},
        passwd => $config{passwd},
    );
 
    $gdoc->upload($filename, { name => $option{name} || '' });
}
 
sub setup_config {
    my $config = eval { YAML::LoadFile($conf) } || {};
    %config = %$config;
 
    $config{email} ||= prompt('email:');
    $config{passwd} ||= prompt('passwd:');
}
 
sub save_config {
    YAML::DumpFile($conf, \%config);
    chmod 0600, $conf;
}
 
__END__
 
=head1 NAME
 
gdoc-upload.pl - Upload documents to Google Docs.
 
=head1 SYNOPSIS
 
gdoc-upload.pl [options] /path/to/documents
Options:
-n --name name what you want call it in gdocs
-h --help show this help
 
=head1 AUTHOR
 
Daisuke Murase <typester@cpan.org>
 
=cut