File Coverage

blib/lib/App/Twirc/Plugin/SecondaryAccount.pm
Criterion Covered Total %
statement 25 25 100.0
branch 6 6 100.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 37 39 94.8


line stmt bran cond sub pod time code
1             package App::Twirc::Plugin::SecondaryAccount;
2             $App::Twirc::Plugin::SecondaryAccount::VERSION = '0.20';
3 1     1   753 use Moose;
  1         309650  
  1         8  
4 1     1   4865 use Net::Twitter;
  1         1  
  1         19  
5 1     1   599 use POE::Component::Server::Twirc;
  1         4  
  1         397  
6              
7             has net_twitter_options => ( isa => 'HashRef', is => 'ro', default => sub { {} } );
8             has username => ( isa => 'Str', is => 'ro', required => 1 );
9             has password => ( isa => 'Str', is => 'ro', required => 1 );
10             has option => ( isa => 'Str', is => 'ro' );
11             has _twitter => ( isa => 'Net::Twitter', is => 'rw' );
12             has _option_regex => ( isa => 'Maybe[RegexpRef]', is => 'rw', default => undef );
13             has _useragent_class => ( isa => 'Str', is => 'ro', default => 'LWP::UserAgent::POE' );
14              
15             sub BUILD {
16 2     2 0 3 my $self = shift;
17              
18 2         52 $self->_twitter(Net::Twitter->new(
19             username => $self->username,
20             password => $self->password,
21             source => 'twircgw',
22             useragent => 'twirc/' . POE::Component::Server::Twirc->VERSION,
23             useragent_class => $self->_useragent_class,
24 2         58 %{$self->net_twitter_options},
25             ));
26              
27 2 100       55 if ( $self->option ) {
28 1         24 my $option = quotemeta $self->option;
29 1         51 $self->_option_regex(qr/^-$option(only)?\s+/);
30             }
31             }
32              
33             sub cmd_post {
34 4     4 0 14 my ($self, $server, $channel, $nick, $textref) = @_;
35              
36 4         4 my $only;
37 4 100       112 if ( my $option_regex = $self->_option_regex ) {
38 3 100       16 $$textref =~ s/$option_regex// || return;
39 2         4 $only = $1;
40             }
41              
42 3         75 $self->_twitter->update($$textref);
43 3         21 return $only; # return a true value to stop the processing chain
44             }
45              
46 1     1   8 no Moose;
  1         1  
  1         6  
47              
48             __PACKAGE__->meta->make_immutable;
49              
50             1;
51              
52             __END__
53              
54             =head1 NAME
55              
56             App::Twirc::Plugin::SecondaryAccount - Cross post updates (DEPRECATED)
57              
58             =head1 SYNOPSIS
59              
60             # in config (.yml in this example)
61             plugins:
62             - SecondaryAccount
63             username: my_other_screen_name
64             password: my_other_twitter_password
65             option: fb
66             - SecondaryAccount
67             username: yet_another_screen_name
68             password: yet_another_password
69             net_twitter_options:
70             apiurl: http://identi.ca/api
71              
72             # In your IRC client...
73             # ...post to your primary account *and* yet_another_screen_name
74             post Hello, world!
75              
76             # ...post to your primary account and both secondary accounts
77             post -fb Hello, universe!
78              
79             # ... post to my_other_screen name, only
80             post -fbonly Hello, alternate reality.
81              
82             =head1 DESCRIPTION
83              
84             This plugin allows cross-posting messages to multiple accounts. In
85             configuration, you can provide an C<option> value. When used as an option to
86             C<post>, your message will be cross-posted to your primary account and the
87             secondary account with that C<option> value. If you do not provide an
88             C<option> value, all messages are cross-posted to the secondary account.
89              
90             By appending C<only> to the C<option> value, your status will only be posted to
91             the the account with that C<option> value.
92              
93             I use a configuration similar to the one in the synopsis to cross-post my
94             Twitter status updates to Identi.ca, and optionally to Facebook. My Twitter
95             screen name is C<semifor>. I created an account with screen name C<semifor_fb>
96             and registered it with Twitter's Facebook application. In the C<twirc>
97             configuration file, I assigned C<option> value C<fb> to the account.
98              
99             I created another secondary account with my Identi.ca screen name. In C<twirc>
100             configuration, I used the C<net_twitter_options> to specify Identi.ca's
101             C<apiurl>.
102              
103             Now, when I post a normal status update, it is posted to C<semifor> on both
104             Twitter and Identi.ca. If I include a C<-fb> option to post, my status update
105             is posted to Twitter, Identi.ca, and Facebook. If I add a C<-fbonly> option to
106             C<post>, my status update is only posted to the Facebook account.
107              
108             =head1 DEPRCATION NOTICE
109              
110             This module relies on username/password authentication, which Twitter dropped
111             ages ago. The author isn't using this plugin, personally, and suspects no one
112             else is, either. So, if you are using it, file an issue, or better---a pull
113             request. Otherwise, it will get silently dropped in a future release.
114              
115             =head1 AUTHOR
116              
117             Marc Mims <mmims@cpan.org>
118              
119             =head1 LICENSE
120              
121             Copyright (c) 2015 Marc Mims
122              
123             You may distribute this code and/or modify it under the same terms as Perl itself.
124              
125             =cut