Geo/Hashing/Source/Peeron.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 5 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 64.0% 41 / 64 CC 10 SCAR 26.0
CC
10
Cov
72%
get_djia
18.4
BEGIN
1.0
BEGIN
1.0
CRAP 13.4
« Geo/Hashing.pm ↑ Summary sample.pl »
1 #!/usr/bin/perl -w
2 #
3 # $Id: Peeron.pm 255 2008-06-21 03:48:46Z dan $
4 #
5  
6 package Geo::Hashing::Source::Peeron;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 require Exporter;
12 1 ▶use LWP::Simple qw/$ua get/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 Geo::Hashing::Source::Peeron - Retrieve DJIA opening values from irc.peeron.com
17  
18 =head1 SYNOPSIS
19  
20 use Geo::Hashing;
21 my $g = new Geo::Hashing(source => 'peeron');
22 printf "Today's offset is at %.6f, %.6f.\n", $g->lat, $g->lon;
23  
24 =head1 DESCRIPTION
25  
26 See documentation of Geo::Hashing.
27  
28 =cut
29  
30 1 $ua->agent("Geo::Hashing/" . $Geo::Hashing::VERSION);
31 1 my $URL = "http://irc.peeron.com/xkcd/map/data/%04d/%02d/%02d";
32  
33 1 our @ISA = qw/Exporter/;
34 1 our @EXPORT = qw/get_djia/;
35  
36 14 ▶sub get_djia {
Subroutine get_djia: called CC=10 SCAR=29.1
Pod undocumented
37 14 my $self = shift;
38 14 my $date = shift;
39  
40 14 ▶ croak "Invalid call to get_djia - missing date!" unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 14 14
41  
42 14 my ($y, $m, $d) = split /-/, $date, 3;
43 14 ▶ croak "Invalid year $y" unless $y and $y >= 1928;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $y >= 1928 0 14 14
Condition33%1/3
$y and $y >= 1928
!ll&&!rl&&r
0014
MC/DC0%0/2
$y and $y >= 1928
$y $y >= 1928
Truth table33%1/3
A and B
A= $yB= $y >= 1928
ABresult
0X0
100
111
44 14 ▶ croak "Invalid month $m" unless $m and $m >= 1 and $m <= 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $m and $m >= 1 and $m <= 12 0 14 14
Condition33%2/6
$m and $m >= 1 and $m <= 12
!ll&&!rl&&r
0014
$m and $m >= 1
!ll&&!rl&&r
0014
MC/DC0%0/3
$m and $m >= 1 and $m <= 12
$m $m >= 1 $m <= 12
Truth table25%1/4
A and B and C
A= $mB= $m >= 1C= $m <= 12
ABCresult
0XX0
10X0
1100
1111
45 14 ▶ croak "Invalid day $d" unless $d and $d >= 1 and $m <= 31;
Branch: 1 branch
BranchTrueFalseTotal
unless $d and $d >= 1 and $m <= 31 0 14 14
Condition33%2/6
$d and $d >= 1 and $m <= 31
!ll&&!rl&&r
0014
$d and $d >= 1
!ll&&!rl&&r
0014
MC/DC0%0/3
$d and $d >= 1 and $m <= 31
$d $d >= 1 $m <= 31
Truth table25%1/4
A and B and C
A= $dB= $d >= 1C= $m <= 31
ABCresult
0XX0
10X0
1100
1111
46  
47 14 my $page = get(sprintf($URL, $y, $m, $d));
48  
49 14 return $page;
50 }
51  
52 =head1 AUTHOR
53  
54 Dan Boger, E<lt>zigdon@gmail.comE<gt>
55  
56 =head1 COPYRIGHT AND LICENSE
57  
58 Copyright (C) 2008 by Dan Boger
59  
60 This library is free software; you can redistribute it and/or modify
61 it under the same terms as Perl itself, either Perl version 5.10.0 or,
62 at your option, any later version of Perl 5 you may have available.
63  
64 =cut
65 1 1;
« Geo/Hashing.pm ↑ Summary sample.pl »