examples/yapc-talk-examples/110-service-unavailable.psgi

filter: Statementstmt 100% 26 / 26 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 100% 37 / 37 CC 2 SCAR 1.8
CC
2
Cov
100%
service_available
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Web/Machine/Util/ContentNegotiation.pm ↑ Summary examples/yapc-talk-examples/120-bind-path.psgi »
1 #!perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Web::Machine;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =pod
9  
10 This demostrates how you can easily handle situations
11 like the site being down in a reasonably elegant way.
12  
13 touch site_down
14 rm site_down
15  
16 =cut
17  
18 {
19 package YAPC::NA::2012::Example110::Resource;
20 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶ use parent 'Web::Machine::Resource';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 ▶ sub content_types_provided { [
Subroutine content_types_provided: called CC=1 SCAR=0.0
26 3 { 'text/html' => 'to_html' },
27 ] }
28  
29 1 ▶ sub to_html { '<html><body><h1>Hello World</h1></body></html>' }
Subroutine to_html: called CC=1 SCAR=0.0
30  
31 2 ▶ sub service_available {
Subroutine service_available: called CC=2 SCAR=6.9
32 2 my $self = shift;
33 2 ▶ return 1 unless -e './site_down';
Branch: 1 branch
BranchTrueFalseTotal
unless -e "./site_down" 1 1 2
34 1 $self->response->body(['<html><body><h1>Service Unavailable</h1>Please come back later.</body></html>']);
35 1 0;
36 }
37 }
38  
39 1 Web::Machine->new( resource => 'YAPC::NA::2012::Example110::Resource' )->to_app;
« blib/lib/Web/Machine/Util/ContentNegotiation.pm ↑ Summary examples/yapc-talk-examples/120-bind-path.psgi »