| 1 | package Acme::Rando; | ||||||||||
| 2 | 2 | $Acme::Rando::VERSION = '0.1'; | |||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use HTTP::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use parent 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | our @EXPORT = qw(rando); | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | Acme::Rando - Get a Random Star Wars quote | ||||||||||
| 17 | |||||||||||
| 18 | =head1 VERSION | ||||||||||
| 19 | |||||||||||
| 20 | version 0.1 | ||||||||||
| 21 | |||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||
| 23 | |||||||||||
| 24 | use Acme::Rando; | ||||||||||
| 25 | |||||||||||
| 26 | say rando(); | ||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | Exports a function rando() which returns a random star wars quote. This joke | ||||||||||
| 31 | probably only makes sense to my coworkers. | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 12 | ▶ | sub rando { | ||||||||
|
Subroutine
rando: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||
| 36 | 12 | my $res = HTTP::Tiny->new->get('http://www.iheartquotes.com/api/v1/random?source=starwars&format=json'); | |||||||||
| 37 | |||||||||||
| 38 | 12 | ▶ | unless ($res->{success}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 12 | return "These aren't the droids you're looking for: $res->{reason}" | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | my $dat = JSON::decode_json($res->{content}); | |||||||||
| 43 | |||||||||||
| 44 | 0 | return $dat->{quote}; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | =head1 AUTHORS | ||||||||||
| 48 | |||||||||||
| 49 | Chris Reinhardt | ||||||||||
| 50 | crein@cpan.org | ||||||||||
| 51 | |||||||||||
| 52 | =head1 COPYRIGHT | ||||||||||
| 53 | |||||||||||
| 54 | This program is free software; you can redistribute | ||||||||||
| 55 | it and/or modify it under the same terms as Perl itself. | ||||||||||
| 56 | |||||||||||
| 57 | The full text of the license can be found in the | ||||||||||
| 58 | LICENSE file included with this module. | ||||||||||
| 59 | |||||||||||
| 60 | =cut | ||||||||||
| 61 | |||||||||||
| 62 | 2 | 1; | |||||||||
| 63 | __END__ | ||||||||||