Skip to content
Newer
Older
100644 28 lines (20 sloc) 617 Bytes
8330129 @tantalor added UN Number goodie
tantalor authored
1 package DDG::Goodie::UN;
2 # ABSTRACT: Gives a description for a given UN number
3
4 use DDG::Goodie;
5 use Number::UN 'get_un';
6
7 use constant WPHREF => "http://en.wikipedia.org/wiki/List_of_UN_numbers_%04d_to_%04d";
8
9 triggers start => 'un';
10
11 handle remainder => sub {
12 my $num = shift or return;
13 my %un = get_un($num) or return;
14 return sprintf "UN Number %04d: %s (%s)", $num, $un{description}, wphref($num);
15 };
16
17 # Wikipedia attribution per CC-BY-SA
18 sub wphref {
19 my $num = shift;
20 my $lower = int($num / 100) * 100 + 1;
21 my $upper = $lower + 99;
22 return sprintf WPHREF, $lower, $upper;
23 }
24
25 zci is_cached => 1;
26
27 1;
Something went wrong with that request. Please try again.