diff --git a/lib/DDG/Goodie/PublicDNS.pm b/lib/DDG/Goodie/PublicDNS.pm
index 41167d797..d1ea9713e 100644
--- a/lib/DDG/Goodie/PublicDNS.pm
+++ b/lib/DDG/Goodie/PublicDNS.pm
@@ -2,6 +2,8 @@ package DDG::Goodie::PublicDNS;
use DDG::Goodie;
+use List::Util qw(max);
+
primary_example_queries 'public dns';
description 'list common public DNS servers and their IP addresses';
name 'Public DNS';
@@ -13,14 +15,124 @@ attribution github => ['https://github.com/warthurton', 'warthurton'];
triggers end => "public dns", "dns servers";
-zci is_cached => 1;
+zci is_cached => 1;
zci answer_type => "public_dns";
-my $text = share('publicdns.txt')->slurp;
-my $html = share('publicdns.html')->slurp;
+# Let them add new entries anywhere, but store them lexically.
+# Done like this to allow for manual (or other) sorting should the
+# need arise.
+my @ordered_servers = sort { $a->{provider} cmp $b->{provider} } ({
+ provider => 'Comodo Secure DNS',
+ ip4 => ['8.26.56.26', '8.20.247.20'],
+ ip6 => [],
+ info_url => 'http://www.comodo.com/secure-dns/',
+ },
+ {
+ provider => 'DNS Advantage',
+ ip4 => ['156.154.70.1', '156.154.71.1'],
+ ip6 => [],
+ info_url => 'http://dnsadvantage.com',
+ },
+ {
+ provider => 'Google Public DNS',
+ ip4 => ['8.8.8.8', '8.8.4.4'],
+ ip6 => ['2001:4860:4860::8888', '2001:4860:4860::8844'],
+ info_url => 'http://code.google.com/speed/public-dns/',
+ },
+ {
+ provider => 'Norton DNS',
+ ip4 => ['198.153.192.1', '198.153.194.1'],
+ ip6 => [],
+ info_url => 'http://dns.norton.com',
+ },
+ {
+ provider => 'OpenDNS',
+ ip4 => ['208.67.222.222', '208.67.220.220'],
+ ip6 => [],
+ info_url => 'http://opendns.com/',
+ },
+);
+
+# Today we could just change and use the key names, but I have no idea what the future holds.
+my @display_cols = ({
+ key => 'provider',
+ title => 'Provider',
+ },
+ {
+ key => 'ip4',
+ title => 'IPv4',
+ },
+ {
+ key => 'ip6',
+ title => 'IPv6',
+ },
+);
+
+my $layout = {
+ extra_space => 1, # How many extra spaces in the text table?
+ text_corner => '+',
+ text_line => '-',
+ text_col => '|',
+ text_array => ', ',
+ html_array => '
',
+};
+
+foreach my $column (@display_cols) {
+ $column->{width} = max(map { _max_str_len($_->{$column->{key}}) } @ordered_servers);
+ $column->{text_spacer} = sub {
+ my $to_show = shift;
+ # Everything is left-aligned
+ return
+ $layout->{text_col}
+ . (' ' x $layout->{extra_space})
+ . $to_show
+ . (' ' x max(0, $column->{width} - length($to_show) + $layout->{extra_space}));
+ };
+}
+
+my $table_spacer =
+ join($layout->{text_corner}, '', (map { $layout->{text_line} x ($_->{width} + $layout->{extra_space} * 2) } @display_cols), '') . "\n";
+
+# Actually build the output.. finally!
+my $text = $table_spacer;
+my $css = share("style.css")->slurp;
+my $html = '
' . join(' | ', map { $_->{title} } @display_cols) . ' |
---|---|
' . (join($layout->{html_array}, @{$server->{$column->{key}}})) . ' | '; + } else { + # Special-case provider + $text .= $column->{text_spacer}->($server->{$column->{key}}); + $html .= '' . $server->{$column->{key}} . ' | '; + } + } + $text .= $layout->{text_col} . "\n"; + $html .= '