| 1 | package HTTP::Engine::Middleware::Status; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use HTTP::Engine::Middleware; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use HTTP::Engine::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Any::Moose '::Util::TypeConstraints'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | subtype 'HTTP::Engine::Middleware::Status::Plugin' | ||||||||||||||||||||||||||||
| 8 | => as 'Object' | ||||||||||||||||||||||||||||
| 9 | 6 | ▶ | => where { $_->isa('HTTP::Engine::Middleware::Status::Base') }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | subtype 'HTTP::Engine::Middleware::Status::Plugins' | |||||||||||||||||||||||||||
| 12 | => as 'ArrayRef[HTTP::Engine::Middleware::Status::Plugin]'; | ||||||||||||||||||||||||||||
| 13 | coerce 'HTTP::Engine::Middleware::Status::Plugins' | ||||||||||||||||||||||||||||
| 14 | => from 'ArrayRef[HashRef]' => via { | ||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $build = []; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 16 | 1 | for my $plugin (@{ $_ }) { | |||||||||||||||||||||||||||
| 17 | 1 | my $module = $plugin->{module}; | |||||||||||||||||||||||||||
| 18 | 1 | ▶ | my $config = $plugin->{config} || +{}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$plugin->{'config'} || {}
MC/DC0%0/1
$plugin->{'config'} || {}
$plugin->{'config'}
Truth table50%1/2
A
A= $plugin->{'config'}
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | $module = __PACKAGE__ . "::$module" unless $module =~ s/^\+//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | Any::Moose::load_class($module); | |||||||||||||||||||||||||||
| 21 | 1 | push @{ $build }, $module->new(%{ $config }); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 1 | $build; | |||||||||||||||||||||||||||
| 24 | 1 | }; | |||||||||||||||||||||||||||
| 25 | coerce 'HTTP::Engine::Middleware::Status::Plugins' | ||||||||||||||||||||||||||||
| 26 | => from 'ArrayRef[Str]' => via { | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $build = []; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 28 | 0 | for my $module (@{ $_ }) { | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | $module = __PACKAGE__ . "::$module" unless $module =~ s/^\+//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | Any::Moose::load_class($module); | |||||||||||||||||||||||||||
| 31 | 0 | push @{ $build }, $module->new; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 0 | $build; | |||||||||||||||||||||||||||
| 34 | 1 | }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | has 'launch_at' => ( | |||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||
| 38 | isa => 'Str', | ||||||||||||||||||||||||||||
| 39 | default => '/httpengine-status', | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | has 'plugins' => ( | ||||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||
| 44 | isa => 'HTTP::Engine::Middleware::Status::Plugins', | ||||||||||||||||||||||||||||
| 45 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 1 | coerce => 1, | |||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub run_hook { | ||||||||||||||||||||||||||||
| 50 | 3 | ▶ | my($self, $hook, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run_hook: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 3 | my @rets; | |||||||||||||||||||||||||||
| 52 | 3 | ▶ | if ($hook eq 'render') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 3 | for my $plugin (@{ $self->plugins }) { | |||||||||||||||||||||||||||
| 54 | 2 | push @rets, $plugin->render_header(%args), $plugin->render(%args); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 0 | for my $plugin (@{ $self->plugins }) { | |||||||||||||||||||||||||||
| 58 | 0 | push @rets, $plugin->$hook(%args); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 3 | @rets; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | before_handle { | ||||||||||||||||||||||||||||
| 65 | 9 | ▶ | my ( $c, $self, $req ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 9 | my $launch_at = $self->launch_at; | |||||||||||||||||||||||||||
| 68 | 9 | ▶ | unless ($launch_at && $req->uri->path =~ /^$launch_at/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$launch_at and $req->uri->path =~ /^$launch_at/
MC/DC50%1/2
$launch_at and $req->uri->path =~ /^$launch_at/
$launch_at
$req->uri->path =~ /^$launch_at/
Truth table66%2/3
A and B
A= $launch_atB= $req->uri->path =~ /^$launch_at/
| |||||||||||||||||||||||||||||
| 69 | # $self->run_hook('before'); | ||||||||||||||||||||||||||||
| 70 | 6 | return $req; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | my $plugin_htmls = join '', $self->run_hook('render', req => $req); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | my $html =<<HTML; | |||||||||||||||||||||||||||
| 76 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||||||||||||||||||||||||||||
| 77 | "http://www.w3.org/TR/html4/loose.dtd"> | ||||||||||||||||||||||||||||
| 78 | <html> | ||||||||||||||||||||||||||||
| 79 | <head> | ||||||||||||||||||||||||||||
| 80 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||||||||||||||||||||||||||||
| 81 | <meta http-equiv="Content-Script-Type" content="text/javascript"> | ||||||||||||||||||||||||||||
| 82 | <meta http-equiv="Content-Style-Type" content="text/css"> | ||||||||||||||||||||||||||||
| 83 | <title>HTTP::Engine Status</title> | ||||||||||||||||||||||||||||
| 84 | </head> | ||||||||||||||||||||||||||||
| 85 | <body> | ||||||||||||||||||||||||||||
| 86 | <h1>HTTP::Engine Status</h1> | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $plugin_htmls | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | </body> | ||||||||||||||||||||||||||||
| 91 | </html> | ||||||||||||||||||||||||||||
| 92 | HTML | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | HTTP::Engine::Response->new( body => $html );; | |||||||||||||||||||||||||||
| 95 | 1 | }; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | __MIDDLEWARE__ | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 NAME | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | HTTP::Engine::Middleware::Status - server status manager | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | my $mw = HTTP::Engine::Middleware->new; | ||||||||||||||||||||||||||||
| 108 | $mw->install( 'HTTP::Engine::Middleware::Status' => { | ||||||||||||||||||||||||||||
| 109 | launch_at => '/hem-server-status', | ||||||||||||||||||||||||||||
| 110 | plugins => [ | ||||||||||||||||||||||||||||
| 111 | 'Memory', # use HTTP::Engine::Middleware::Status::Memory | ||||||||||||||||||||||||||||
| 112 | ], | ||||||||||||||||||||||||||||
| 113 | }); | ||||||||||||||||||||||||||||
| 114 | HTTP::Engine->new( | ||||||||||||||||||||||||||||
| 115 | interface => { | ||||||||||||||||||||||||||||
| 116 | module => 'YourFavoriteInterfaceHere', | ||||||||||||||||||||||||||||
| 117 | request_handler => $mw->handler( \&handler ), | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | )->run(); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # $ GET http//localhost/hem-server-status | ||||||||||||||||||||||||||||
| 122 | # to get the status contents | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | this module is given server status contents like Apache's mod_status.c to HTTP::Engine. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | L<HTTP::Engine::Middleware::Status::Memory> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Kazuhiro Osawa | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||