blib/lib/Dezi/UI.pm

filter: Statementstmt 53.4% 23 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 2 / 2 totaltotal 55.1% 32 / 58 CC 3 SCAR 14.1
CC
3
Cov
49%
call
12.0
default_page
2.0
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package Dezi::UI;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base qw( Plack::Middleware );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Plack::Util::Accessor qw( base_uri search_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Data::Dump qw( dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.001005';
12  
13 =head1 NAME
14  
15 Dezi::UI - HTML interface to a Dezi server
16  
17 =head1 SYNOPSIS
18  
19 % dezi --ui-class=Dezi::UI
20  
21 =head1 DESCRIPTION
22  
23 Dezi::UI is an example HTML interface for exploring a Dezi server.
24 Dezi::UI isa Plack::Middleware.
25  
26 =head1 METHODS
27  
28 =head2 default_page
29  
30 Returns the HTML string suitable for the main UI. It uses
31 the jQuery-based examples from dezi.org.
32  
33 =cut
34  
35 0 ▶sub default_page {
Subroutine default_page: not called CC=1 SCAR=6.9
Pod documented
36 0 return <<EOF;
37 <html>
38 <head>
39 <title>Dezi UI</title>
40 <link rel="stylesheet" type="text/css" href="//dezi.org/ui/example/dezi-ui.css" />
41 <script type="text/javascript">var DEZI_SEARCH_URI = 'REPLACE_ME';</script>
42 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
43 <script src="//dezi.org/ui/example/jquery.ba-bbq.js" type='text/javascript'></script>
44 <script src="//dezi.org/ui/example/dezi-ui-jquery.js" type='text/javascript'></script>
45 </head>
46 <body></body>
47 </html>
48 EOF
49  
50 }
51  
52 =head2 call( I<env> )
53  
54 Implements the required Middleware method. GET requests
55 are the only allowed interface.
56  
57 =cut
58  
59 0 ▶sub call {
Subroutine call: not called CC=3 SCAR=24.8
Pod documented
60 0 my ( $self, $env ) = @_;
61 0 my $req = Plack::Request->new($env);
62 0 my $path = $req->path;
63 0 my $resp = $req->new_response;
64 0 ▶ if ( $req->method eq 'GET' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->method eq 'GET') { } 0 0 0
65 0 $resp->status(200);
66 0 $resp->content_type('text/html');
67 0 my $body = $self->default_page;
68 0 my $search_uri;
69 0 ▶ if ($self->base_uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->base_uri) { } 0 0 0
70 0 $search_uri = $self->base_uri . $self->search_path;
71 }
72 else {
73 0 my $uri = $req->base;
74 0 $uri =~ s,/ui,,;
75 0 $search_uri = $uri . $self->search_path;
76 }
77 0 $body =~ s,REPLACE_ME,$search_uri,g;
78 0 $resp->body($body);
79 }
80 else {
81 0 $resp->status(400);
82 0 $resp->body('GET only allowed');
83 }
84 0 return $resp->finalize;
85 }
86  
87 2 1;
88  
89 __END__
↑ Summary