blib/lib/Net/Generatus.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 56 CC 2 SCAR 11.5
CC
2
Cov
0%
Status
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Net::Generatus;
2  
3 use warnings;
4 use strict;
5 use base qw/Net/;
6 use URI::Escape;
7 use LWP::UserAgent;
8 #use Carp;
9  
10 our $VERSION = '0.40';
11 #http://search.twitter.com/search.json?q=<query>
12  
13 sub Status {
14 my $self = shift;
15 #$self->set_user_agent("Net::Generatus-$VERSION (PERL)");
16  
17 my $params = shift || {};
18  
19 #grab the params
20 my $gender = $params->{'gender'} || 'F';
21 my $name = $params->{'name'} || '';
22 my $tag = $params->{'tag'} || '';
23
24 #build URL
25 my $url = 'http://www.generatus.com/AJAXStatus.asp?';
26  
27 $url .= 'G=' . URI::Escape::uri_escape($gender);
28 $url .= '&N=' . URI::Escape::uri_escape($name);# if ($name);
29 $url .= '&K=' . URI::Escape::uri_escape($tag); # if ($tag);
30  
31 #do request
32 my $ua = LWP::UserAgent->new();
33 #my $req = $self->{ua}->get($url);
34 my $response = $ua->post($url);
35
36 my $raw;
37 if ($response->is_success) {
38 $raw = $response->decoded_content; # or whatever
39 }
40 else {
41 die $response->status_line;
42 }
43  
44 my @bits = split(/\#\#\#/, $raw);
45 my $status = $bits[0];
46 chomp $status;
47 return $status;
48 }
49  
50 # sub set_user_agent {
51 # my $self = shift;
52 # my $agent = shift;
53 # $self->{ua}->agent($agent);
54 # }
55  
56 1;
57  
58 =head1 NAME
59  
60 Net::Generatus - Get random status message from generatus.com
61  
62 =head1 SYNOPSYS
63  
64 use Net::Generatus;
65 #get an interesting yet rude status message
66 $status = Net::Generatus::Status({tag => 'insults'});
67  
68  
69
70 =head1 DESCRIPTION
71  
72 Pulls a random and potentially witty status message from generatus.com which could be used to update twitter or one of it's clones
73  
74 =head1 METHODS
75  
76 =head2 Status
77  
78 params
79 tag - (optional) select the status message from message with this tag
80 name - (your name, optional, will be prepended to status message)
81 gender - either M or F (defaults to F)
82 returns: string
83  
84 =head2 EXAMPLE
85  
86 #get a insults status message
87 $status = Net::Generatus::Status({tag => 'insults'});
88
89 $status = Net::Generatus::Status({gender => 'M'});
90  
91 =head1 AUTHOR
92  
93 Brenda Wallace <shiny@cpan.org>
94  
95 (based on Net::Twitter::Search and Net::Twitter::Diff)
96  
97 =cut