| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Fortune::WWW::Postillion; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
31026
|
use 5.010; |
|
|
1
|
|
|
|
|
122
|
|
|
|
1
|
|
|
|
|
43
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
1
|
|
|
1
|
|
2016
|
use WWW::Mechanize; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use HTML::Parser; |
|
8
|
|
|
|
|
|
|
use base 'Exporter::Tiny'; |
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw/cookie/; |
|
10
|
|
|
|
|
|
|
use Mojo::UserAgent; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Fortune::WWW::Postillion - Get fortune cookies from http://www.der-postillion.com! |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Fortune::WWW::Postillion gives you fortune cookies from the newsticker archive |
|
25
|
|
|
|
|
|
|
of the webside C. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Fortune::WWW::Postillion 'cookie'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $random_cookie = cookie(); |
|
31
|
|
|
|
|
|
|
my $third_cookie = cookie(3); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 EXPORT |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
our @text; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub text_handler |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
|
|
|
|
|
|
my ($self, $text) = @_; |
|
44
|
|
|
|
|
|
|
if ($text =~ m/[+]{4}\s*(.+?)\s*[+]{4}/) { |
|
45
|
|
|
|
|
|
|
push @text, $1; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SUBROUTINES |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 cookie |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Get a new fortune cookie. You can either request a random cookie or give a |
|
54
|
|
|
|
|
|
|
number n and the module will try to return the nth element of the cookie |
|
55
|
|
|
|
|
|
|
list. The number is used modulo the number of elements in the cookie jar. So |
|
56
|
|
|
|
|
|
|
if you ask for the 5th cookie in a 4 element jar, you will get the first one. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
@param int - number of element in news list |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
@return success - string |
|
61
|
|
|
|
|
|
|
@return error - exception |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
@throws die() |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub cookie |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
|
|
|
|
|
|
my ($num_cookie) = @_; |
|
70
|
|
|
|
|
|
|
my $url = 'http://www.der-postillon.com/search/label/Newsticker'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
|
73
|
|
|
|
|
|
|
my $body = $ua->get($url)->res->body; |
|
74
|
|
|
|
|
|
|
# Create parser object |
|
75
|
|
|
|
|
|
|
my $parser = HTML::Parser->new(); |
|
76
|
|
|
|
|
|
|
$parser->handler(text => \&text_handler); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$parser->parse($body); |
|
79
|
|
|
|
|
|
|
$parser->eof; |
|
80
|
|
|
|
|
|
|
if (not $num_cookie) { |
|
81
|
|
|
|
|
|
|
$num_cookie = int(rand(@text)) + 1; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return $text[($num_cookie-1) % int @text]; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Maik Hentsche, C<< >> |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
95
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
96
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SUPPORT |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
perldoc Fortune::WWW::Postillion |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
You can also look for information at: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * Search CPAN |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright 2012 Maik Hentsche. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
139
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
140
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; # End of Fortune::WWW::Postillion |