These days I tend to prefer using the Web over building GUIs.
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=a
+uthor:$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]-bas
+e");
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" ],
];
};
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|