use LWP::UserAgent; use JSON qw(from_json); use HTML::HTML5::Builder qw(:standard); use List::Util qw(shuffle); my $rows = 4; my $cols = 4; my $size = 60; my $whom = 'TOBYINK'; my %foregrounds = ( magenta => 'black', red => 'white', orange => 'black', yellow => 'black', lime => 'black', green => 'white', cyan => 'black', blue => 'white', purple => 'white', ); my @colours = keys %foregrounds; my @chosen_links; my @links = map { $_->{fields}{name} =~ m/^(.+)-([^-]+)$/; $1 } @{ from_json( LWP::UserAgent -> new() -> get("http://api.metacpan.org/v0/release/_search?q=author:$whom+AND+status:latest&fields=name&size=200") -> decoded_content )->{hits}{hits} }; my $hexstyle = qq{ h1 { margin: 0; padding: 0 } .col { width: @{[ 3.5 * $size ]}px; float: left; } .hex { border: ${size}px solid transparent; } .mid { margin: 0; padding: 0; height: 0; border: 1px solid transparent; overflow: visible; text-align: center; } .mid p { position: relative; top: -1.2em; font-size: 75%; } a:link { color: inherit !important; text-decoration: none; } a:visited { color: inherit !important; text-decoration: line-through; } } .(join q(), map { qq{ #col$_ { position: relative; left: -@{[ $size * ($_-1) ]}px; top: @{[ $_%2 ? 0 : ($size+1) ]}px; } } } 2 .. $cols) .(join q(), map { qq{ .${_} { border-color: $_; color: $foregrounds{$_} } .${_}-top { border-bottom-color: $_ } /* sic */ .${_}-base { border-top-color: $_ } /* sic */ } } @colours) ; sub mk_column { my $C = shift; my $n = $C%2 ? $rows : ($rows-1); my @chosen_colours = map { $colours[rand(@colours)] } 1 .. $n; my @return; my $i = 0; LOOP: while (1) { if ($i == 0) { push @return, div(-class => "hex $chosen_colours[$i]-top"); } else { push @return, div(-class => "hex $chosen_colours[$i]-top $chosen_colours[$i-1]-base"); } my $href = sprintf('https://metacpan.org/release/%s', $chosen_links[($cols*($C-1)) + $i]); push @return, div( -class => "mid $chosen_colours[$i]", p( a(-href=>$href, $chosen_links[($cols*($C-1)) + $i]) ) ); $i++; if ($i == $n) { push @return, div(-class => "hex $chosen_colours[$i-1]-base"); last LOOP; } } div( -class => 'col', -id => "col$_", @return, ); } my $app = sub { @chosen_links = shuffle @links; my $html = html( head( title("Hexed!"), style(-type => 'text/css', $hexstyle), ), body( h1("Modules by $whom"), map { mk_column($_) } 1..$cols ) ); return [ 200, [ 'Content-Type' => 'text/html' ], [ "$html" ], ]; };