Subject: | Load credentials from $HOME/.bitly file |
I think it would be a nice idea to add a configfile e.g. $HOME/.bitly
to the distribution, so you don't have to specify credentials every time
you shorten a url.
I have included a patch to W::S::B v1.10.
perl -MToolSet::y -e 'print WWW::Shorten::Bitly->new->shorten(URL=>pop)'
"http://search.cpan.org/search?query=WWW::Shorten::Bitly"
http://bit.ly/3DzRYP
Subject: | bitlyrc.patch |
--- WWW-Shorten-Bitly-1.10-k9dlNO/lib/WWW/Shorten/Bitly.pm 2009-06-24 13:15:28.000000000 +0200
+++ WWW-Shorten-Bitly-1.10-cIDHiD.mod/lib/WWW/Shorten/Bitly.pm 2009-08-09 21:36:54.000000000 +0200
@@ -97,6 +97,17 @@
my ($class) = shift;
my %args = @_;
$args{source} ||= "perlteknatusbitly";
+ use File::Spec;
+ my $bitlyrc = $^O =~/Win32/i ? File::Spec->catfile($ENV{HOME}, "_bitly")
+ : File::Spec->catfile($ENV{HOME}, ".bitly");
+ if (-r $bitlyrc){
+ open my $fh, "<", $bitlyrc or die "can't open .bitly file $!";
+ while(<$fh>){
+ $args{USER} ||= $1 if m{^USER=(.*)};
+ $args{APIKEY} ||= $1 if m{^APIKEY=(.*)};
+ }
+ close $fh;
+ }
if (!defined $args{USER} || !defined $args{APIKEY}) {
carp("USER and APIKEY are both required parameters.\n");
return -1;
@@ -303,6 +314,14 @@
return $WWW::Shorten::Bitly::VERSION;
}#version
+=head1 FILES
+
+$HOME/.bitly or _bitly on Windows Systems.
+
+You may omit USER and APIKEY in the constructor if you set them in the .bitly config file on separate lines using the syntax:
+
+USER=username
+APIKEY=apikey
=head1 AUTHOR