Dist-Zilla-Plugin-Twitter
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Twitter.pm view on Meta::CPAN
},
);
has 'consumer_tokens' => (
is => 'ro',
isa => 'HashRef',
lazy => 1,
default => sub {
return { grep tr/a-zA-Z/n-za-mN-ZA-M/, map $_, # rot13
pbafhzre_xrl => 'fdAdffgTXj6OiyoH0anN',
pbafhzre_frperg => '3J25ATbGmgVf1vO0miwz3o7VjRoXC7Y9y5EfLGaUfTL',
};
},
);
has 'twitter' => (
is => 'ro',
isa => 'Net::Twitter',
lazy => 1,
default => sub {
my $self = shift;
my $nt = Net::Twitter->new(
useragent_class => $ENV{DZ_TWITTER_USERAGENT} || 'LWP::UserAgent',
traits => [qw/ API::RESTv1_1 OAuth /],
ssl => 1,
%{ $self->consumer_tokens },
);
try {
require Config::INI::Reader;
my $access = Config::INI::Reader->read_file( $self->config_file );
$nt->access_token( $access->{'api.twitter.com'}->{access_token} );
$nt->access_token_secret( $access->{'api.twitter.com'}->{access_secret} );
}
catch {
$self->log("Error: $_");
my $auth_url = $nt->get_authorization_url;
$self->log(__PACKAGE__ . " isn't authorized to tweet on your behalf yet");
$self->log("Go to $auth_url to authorize this application");
my $pin = $self->zilla->chrome->prompt_str('Enter the PIN: ');
chomp $pin;
# Fetches tokens and sets them in the Net::Twitter object
my @access_tokens = $nt->request_access_token(verifier => $pin);
unless ( -d $self->config_dir ) {
require File::Path;
File::Path::make_path( $self->config_dir );
}
require Config::INI::Writer;
Config::INI::Writer->write_file( {
'api.twitter.com' => {
access_token => $access_tokens[0],
access_secret => $access_tokens[1],
}
}, $self->config_file );
try {
chmod 0600, $self-> config_file;
}
catch {
print "Couldn't make @{[ $self->config_file ]} private: $_";
};
};
return $nt;
},
);
# methods
sub after_release {
my $self = shift;
my $tgz = shift || 'unknowntarball';
my $zilla = $self->zilla;
my $cpan_id = '';
for my $plugin ( @{ $zilla->plugins_with( -Releaser ) } ) {
if ( my $user = eval { $plugin->user } || eval { $plugin->username } ) {
$cpan_id = uc $user;
last;
}
}
confess "Can't determine your CPAN user id from a release plugin"
unless length $cpan_id;
my $path = substr($cpan_id,0,1)."/".substr($cpan_id,0,2)."/$cpan_id";
my $stash = {
DIST => $zilla->name,
ABSTRACT => $zilla->abstract,
VERSION => $zilla->version,
TRIAL => ( $zilla->is_trial ? '-TRIAL' : '' ),
TARBALL => "$tgz",
AUTHOR_UC => $cpan_id,
AUTHOR_LC => lc $cpan_id,
AUTHOR_PATH => $path,
};
my $module = $zilla->name;
$module =~ s/-/::/g;
$stash->{MODULE} = $module;
my $longurl = $self->fill_in_string($self->tweet_url, $stash);
$stash->{URL} = $self->_shorten( $longurl );
my $msg = $self->fill_in_string( $self->tweet, $stash);
$DB::single = 1;
{
no warnings qw/ uninitialized /;
$msg =~ s/
(?<modifier>[!@]?)
META
(?<access>
(?:
\{ [^}]+ \}
|
( run in 0.835 second using v1.01-cache-2.11-cpan-39bf76dae61 )