blib/lib/Bot/BasicBot/Pluggable/Module/SubReddit.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 94.5% 35 / 37 CC 3 SCAR 5.8
CC
3
Cov
96%
told
3.0
help
2.0
BEGIN
1.0
CRAP 1.8
↑ Summary
1 package Bot::BasicBot::Pluggable::Module::SubReddit;
2  
3 2 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use URI::Title qw/title/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Bot::BasicBot::Pluggable::Module::SubReddit - a simple reddit-related helper plugin for Bot::BasicBot::Pluggable
13  
14 =head1 VERSION
15  
16 Version 0.02
17  
18 =cut
19  
20 2 our $VERSION = '0.02';
21  
22 =head1 SYNOPSIS
23  
24 Spots likely subreddit links (e.g. "r/perl" or "/r/dailyprogrammer") and replies with the URL and description of the subreddit.
25  
26 $bot->load('SubReddit');
27  
28 No, really, that's it.
29  
30 =cut
31  
32 =head1 IRC Usage
33  
34 Just mention the a subreddit and the bot will offer a link and some details.
35  
36 01:38:12 <jkg> r/AskReddit
37 01:38:12 <hadaly> Reddit: http://www.reddit.com/r/AskReddit -- Ask Reddit...
38 01:38:25 <jkg> r/IAmA
39 01:38:26 <hadaly> Reddit: http://www.reddit.com/r/IAmA -- I Am A, where the mundane becomes fascinating and the outrageous suddenly seems normal.
40 01:38:36 <jkg> /r/bifl
41 01:38:36 <hadaly> Reddit: http://www.reddit.com/r/bifl -- Buy it for life
42  
43 =cut
44  
45 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
46 0 return "Links to, and describes, subreddits mentioned as /r/subname";
47 }
48  
49 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
50 1 my $self = shift;
51 1 $self->config(
52 {} # nothing to configure yet; might add API-fu later though
53 );
54 }
55  
56 2 ▶sub told {
Subroutine told: called CC=3 SCAR=11.0
Pod documented
57  
58 2 my ( $self, $mess ) = @_;
59  
60 2 for ( split / /, $mess->{body} ) {
61  
62 4 ▶ next unless $_ =~ m!^/?(r/[A-Za-z0-9_]+)[;,]?!; # does this look like a subreddit name?
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ m[^/?(r/[A-Za-z0-9_]+)[;,]?] 2 2 4
63  
64 2 my $url = "http://www.reddit.com/$1";
65  
66 2 my $title = title($url);
67 #next unless defined $title;
68  
69 2 my $result = "Reddit: $url -- $title";
70 2 $self->reply( $mess, $result );
71 }
72  
73 2 return; # Title.pm is passive, and doesn't intercept things.
74 # and we want to be just like Title.pm when we grow up
75 }
76  
77 =head1 AUTHOR
78  
79 James Green, C<< <jkg at cpan.org> >>
80  
81 =head1 BUGS
82  
83 Please report any bugs or feature requests to C<bug-bot-basicbot-pluggable-module-subreddit at rt.cpan.org>, or through
84 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bot-BasicBot-Pluggable-Module-SubReddit>. I will be notified, and then you'll
85 automatically be notified of progress on your bug as I make changes.
86  
87  
88  
89  
90 =head1 SUPPORT
91  
92 You can find documentation for this module with the perldoc command.
93  
94 perldoc Bot::BasicBot::Pluggable::Module::SubReddit
95  
96  
97 You can also look for information at:
98  
99 =over 4
100  
101 =item * RT: CPAN's request tracker (report bugs here)
102  
103 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bot-BasicBot-Pluggable-Module-SubReddit>
104  
105 =item * AnnoCPAN: Annotated CPAN documentation
106  
107 L<http://annocpan.org/dist/Bot-BasicBot-Pluggable-Module-SubReddit>
108  
109 =item * CPAN Ratings
110  
111 L<http://cpanratings.perl.org/d/Bot-BasicBot-Pluggable-Module-SubReddit>
112  
113 =item * Search CPAN
114  
115 L<http://search.cpan.org/dist/Bot-BasicBot-Pluggable-Module-SubReddit/>
116  
117 =back
118  
119  
120 =head1 ACKNOWLEDGEMENTS
121  
122  
123 =head1 LICENSE AND COPYRIGHT
124  
125 Copyright 2014 James Green.
126  
127 This program is free software; you can redistribute it and/or modify it
128 under the terms of the the Artistic License (2.0). You may obtain a
129 copy of the full license at:
130  
131 L<http://www.perlfoundation.org/artistic_license_2_0>
132  
133 Any use, modification, and distribution of the Standard or Modified
134 Versions is governed by this Artistic License. By using, modifying or
135 distributing the Package, you accept this license. Do not use, modify,
136 or distribute the Package, if you do not accept this license.
137  
138 If your Modified Version has been derived from a Modified Version made
139 by someone other than you, you are nevertheless required to ensure that
140 your Modified Version complies with the requirements of this license.
141  
142 This license does not grant you the right to use any trademark, service
143 mark, tradename, or logo of the Copyright Holder.
144  
145 This license includes the non-exclusive, worldwide, free-of-charge
146 patent license to make, have made, use, offer to sell, sell, import and
147 otherwise transfer the Package with respect to any patent claims
148 licensable by the Copyright Holder that are necessarily infringed by the
149 Package. If you institute patent litigation (including a cross-claim or
150 counterclaim) against any party alleging that the Package constitutes
151 direct or contributory patent infringement, then this Artistic License
152 to you shall terminate on the date that such litigation is filed.
153  
154 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
155 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
156 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
157 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
158 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
159 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
160 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
161 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162  
163  
164 =cut
165  
166 2 42; # End of Bot::BasicBot::Pluggable::Module::SubReddit
↑ Summary