| 1 | package App::tmblr; | ||
| 2 | |||
| 3 | use WWW::Tumblr; | ||
| 4 | |||
| 5 | our $VERSION = '0.04'; | ||
| 6 | |||
| 7 | our $skellington = <<'END'; | ||
| 8 | $blog = '???.tumblr.com'; | ||
| 9 | $tokens = { | ||
| 10 | consumer_key => '', | ||
| 11 | secret_key => '', | ||
| 12 | token => '', | ||
| 13 | token_secret => '' | ||
| 14 | }; | ||
| 15 | END | ||
| 16 | |||
| 17 | sub init { | ||
| 18 | our ($blog, $tokens); | ||
| 19 | my $path = shift || "$ENV{HOME}/.tmblr"; | ||
| 20 | $blog = shift; | ||
| 21 | do $path or warn("unable to parse $path") if -f $path; | ||
| 22 | if(!$tokens || !$blog) { | ||
| 23 | say STDERR "put your blog name and your silly tokens in $path"; | ||
| 24 | if(!-f $path) { | ||
| 25 | open(my $fh, ">", $path); | ||
| 26 | say $fh $skellington; | ||
| 27 | close($path); | ||
| 28 | } | ||
| 29 | exit(1); | ||
| 30 | } | ||
| 31 | my $tumblr = WWW::Tumblr->new($tokens); | ||
| 32 | return $tumblr->blog($blog); | ||
| 33 | } | ||
| 34 | |||
| 35 | sub gulp { | ||
| 36 | my $name = shift; | ||
| 37 | my $content; | ||
| 38 | if($name) { | ||
| 39 | if($name eq "-") { | ||
| 40 | $content = join('', <STDIN>); | ||
| 41 | } else { | ||
| 42 | open my $fh, "<", $name; | ||
| 43 | $content = join('', <$fh>); | ||
| 44 | close($fh); | ||
| 45 | } | ||
| 46 | } else { | ||
| 47 | my $tmp = tmpnam(); | ||
| 48 | system($ENV{EDITOR} || "ed", $tmp); | ||
| 49 | open my $fh, '<', $tmp or die "couldn't open temporary file: $!\n"; | ||
| 50 | $content = join('', <$fh>); | ||
| 51 | close $fh; | ||
| 52 | } | ||
| 53 | return $content; | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; |