use HTML::TreeBuilder;
use JSON::MaybeXS qw/encode_json/;
use NetHack::NAOdash qw/naodash_user/;
+use Plack::Request;
my ($dash, $css, $css_hash);
}
sub make_html {
- my ($name, $result) = @_;
+ my ($name, $query, $result) = @_;
my @checks = @{$result->{checks}};
my %numbers = %{$result->{numbers}};
$numbers{totalrealtime} = format_time $numbers{totalrealtime};
warn "No element for check $id" unless $el; ## no critic (RequireCarping)
$el->delete_content->push_content($num);
}
+ my $ahref = $tree->look_down(href => "?$query");
+ $ahref->replace_with(join '', $ahref->content_list) if $ahref;
$tree->as_HTML;
}
sub call {
my ($self, $env) = @_;
- return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $env->{PATH_INFO} =~ m{^/(\w+)$};
+ my $req = Plack::Request->new($env);
+ return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $req->path =~ m{^/(\w+)$};
my $name = $1;
- my $result = eval { naodash_user $name } or return reply 500, $@;
+ my %args = (
+ include_versions => [$req->query_parameters->get_all('include_versions')],
+ exclude_versions => [$req->query_parameters->get_all('exclude_versions')],
+ );
+ my $result = eval { naodash_user \%args, $name } or return reply 500, $@;
return reply 200, encode_json($result), 'application/json' if $self->{json};
- return reply 200, make_html($name, $result), 'text/html';
+ return reply 200, make_html($name, $req->query_string, $result), 'text/html';
}
1;
username. It retrieves the xlogfile from NAO and returns the result of
the analysis.
+Two query parameters are accepted: include_versions and
+exclude_versions, both of which can take multiple values by
+specifiying them multiple times. They are passed directly to the
+B<naodash_user> function, see the documentation of L<NetHack::NAOdash>
+for an explanation of their function.
+
The constructor takes a single named parameter, I<json>, that is false
by default. The result will be returned as HTML is I<json> is false,
as JSON if I<json> is true.