package Dezi::UI; use warnings; use strict; use base qw( Plack::Middleware ); use Carp; use Plack::Request; use Plack::Util::Accessor qw( base_uri search_path ); use Data::Dump qw( dump ); our $VERSION = '0.001005'; =head1 NAME Dezi::UI - HTML interface to a Dezi server =head1 SYNOPSIS % dezi --ui-class=Dezi::UI =head1 DESCRIPTION Dezi::UI is an example HTML interface for exploring a Dezi server. Dezi::UI isa Plack::Middleware. =head1 METHODS =head2 default_page Returns the HTML string suitable for the main UI. It uses the jQuery-based examples from =cut sub default_page { return < Dezi UI EOF } =head2 call( I ) Implements the required Middleware method. GET requests are the only allowed interface. =cut sub call { my ( $self, $env ) = @_; my $req = Plack::Request->new($env); my $path = $req->path; my $resp = $req->new_response; if ( $req->method eq 'GET' ) { $resp->status(200); $resp->content_type('text/html'); my $body = $self->default_page; my $search_uri; if ($self->base_uri) { $search_uri = $self->base_uri . $self->search_path; } else { my $uri = $req->base; $uri =~ s,/ui,,; $search_uri = $uri . $self->search_path; } $body =~ s,REPLACE_ME,$search_uri,g; $resp->body($body); } else { $resp->status(400); $resp->body('GET only allowed'); } return $resp->finalize; } 1; __END__ =head1 AUTHOR Peter Karman, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Dezi::UI You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 COPYRIGHT & LICENSE Copyright 2012 Peter Karman. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See for more information. =cut