HMI.pm

filter: Statementstmt 40.6% 26 / 64 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 9 / 12 Podpod 50.0% 1 / 2 totaltotal 39.1% 36 / 92 CC 7 SCAR 27.3
CC
7
Cov
35%
handler
42.0
new
6.0
__ANON__
2.0
CRAP 15.3
↑ Summary HMI/Catalyst/Controller/Task.pm »
1 package Hopkins::Plugin::HMI;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Hopkins::Plugin::HMI::VERSION = '0.900';
4 }
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Hopkins::Plugin::HMI - hopkins HMI session (using HTTP)
12  
13 =head1 DESCRIPTION
14  
15 Hopkins::Plugin::HMI encapsulates the HMI (human machine
16 interface) POE session created by the manager session. this
17 session uses the Server::HTTP component to provide a web
18 interface to the job server using Catalyst.
19  
20 =cut
21  
22 2 ▶BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' }
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use POE::Component::Server::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 ▶use Class::Accessor::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 __PACKAGE__->mk_accessors(qw(kernel manager config app errmsg));
34  
35 2 our $catalyst;
36  
37 =head1 STATES
38  
39 =over 4
40  
41 =item new
42  
43 =cut
44  
45 sub new
46 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
47 0 my $self = shift->SUPER::new(@_);
48  
49 # load the Catalyst-related bits as late as possible so
50 # that we can give it a dynamic configuration. Catalyst
51 # is not very OO minded, so we have to monkey around
52 # with its worldview.
53  
54 0 $catalyst->{'Plugin::Authentication'} = $self->config->{auth};
55 0 $catalyst->{session} = $self->config->{session};
56 0 $catalyst->{session}->{cookie_name} = 'hopkins-hmi';
57 0 $catalyst->{hopkins} = $self->manager;
58  
59 0 require Hopkins::Plugin::HMI::Catalyst;
60  
61 0 $self->app(new Hopkins::Plugin::HMI::Catalyst);
62  
63 # handle plugin-specific configuration, then create
64 # a POE::Component::Server::HTTP instance that will
65 # dispatch incoming requests to the Catalyst instance.
66  
67 0 ▶ $self->config->{port} ||= 8088;
Condition0%0/2
$self->config->{"port"} ||= 8088
l!l
00
MC/DC0%0/1
$self->config->{"port"} ||= 8088
$self->config->{"port"}
Truth table0%0/2
A
A= $self->config->{"port"}
Aresult
11
00
68  
69 0 $self->errmsg(join '', <DATA>);
70  
71 my %args =
72 (
73 Port => $self->config->{port},
74 0 ▶ ContentHandler => { '/' => sub { $self->handler(@_) } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 Headers => { Server => "hopkins/$Hopkins::VERSION" }
76 );
77  
78 0 new POE::Component::Server::HTTP %args;
79 }
80  
81 sub handler
82 0 ▶{
Subroutine handler: not called CC=6 SCAR=37.4
Pod undocumented
83 0 my $self = shift;
84 0 my $req = shift;
85 0 my $res = shift;
86 0 my $app = $self->app;
87  
88 0 my $obj;
89 my @err;
90  
91 0 my $code = $app->handle_request($req, \$obj, \@err);
92  
93 # if the request failed, show an error page, but use our
94 # own in place of Catalyst's butt ugly one. process the
95 # page using TT in order to show error messages.
96  
97 0 ▶ if (not defined $obj or $code == 500) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $obj or $code == 500) 0 0 0
Condition0%0/3
not defined $obj or $code == 500
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $obj or $code == 500
not defined $obj $code == 500
Truth table0%0/3
not(A) or B
A= not defined $objB= $code == 500
ABresult
1X1
011
000
98 0 my $template = new Template;
99 0 my $stash = { errors => \@err, version => $Hopkins::Plugin::HMI::VERSION };
100 0 my $output = '';
101  
102 0 $template->process(\$self->errmsg, $stash, \$output);
103  
104 0 $res->content($output);
105 0 $res->code(500);
106  
107 0 return RC_OK;
108 }
109  
110 # if the content we get back from is an IO::File object,
111 # flatten it by reading it in and spitting it back out.
112  
113 0 ▶ if (UNIVERSAL::isa($obj->content, 'IO::File')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($obj->content, "IO::File")) 0 0 0
114 0 my $content;
115  
116 0 ▶ while (not eof $obj->content) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $obj->content) 0 0 0
117 0 read $obj->content, my ($buf), 64 * 1024;
118 0 $content .= $buf;
119 }
120  
121 0 $obj->content($content);
122 }
123  
124 # Catalyst::Engine::Embeddable->handle_request populates
125 # a HTTP::Response object, though PoCo::Server::HTTP has
126 # already provided us with one. transcribe the contents
127 # of the catalyst HTTP::Response onto the other instance
128 # provided by POE::Component::Server::HTTP.
129  
130 $res->header($_ => $obj->header($_))
131 0 foreach $obj->headers->header_field_names;
132  
133 0 $res->code($obj->code);
134 0 $res->content($obj->content);
135 0 $res->message('');
136  
137 0 $req->header(Connection => 'close');
138  
139 0 return RC_OK;
140 }
141  
142 =back
143  
144 =head1 AUTHOR
145  
146 Mike Eldridge <diz@cpan.org>
147  
148 =head1 LICENSE
149  
150 This program is free software; you may redistribute it
151 and/or modify it under the same terms as Perl itself.
152  
153 =cut
154  
155 2 1;
156  
157 __DATA__
↑ Summary HMI/Catalyst/Controller/Task.pm »