examples/yapc-talk-examples/030-postback.psgi

filter: Statementstmt 100% 32 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 100% 44 / 44 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« examples/hello-world/app.psgi ↑ Summary examples/yapc-talk-examples/100-add-caching.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  
9 {
10 package YAPC::NA::2012::Example030::Resource;
11 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶ use parent 'Web::Machine::Resource';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @MESSAGES = ();
17 1 ▶ sub save_message { push @MESSAGES => $_[1] }
Subroutine save_message: called CC=1 SCAR=0.0
18 2 ▶ sub get_messages { @MESSAGES }
Subroutine get_messages: called CC=1 SCAR=0.0
19  
20 3 ▶ sub allowed_methods { [qw[ GET POST ]] }
Subroutine allowed_methods: called CC=1 SCAR=0.0
21 8 ▶ sub content_types_provided { [ { 'text/html' => 'to_html' } ] }
Subroutine content_types_provided: called CC=1 SCAR=0.0
22  
23 2 ▶ sub to_html {
Subroutine to_html: called CC=1 SCAR=0.0
24 2 my $self = shift;
25 '<html><body><form method="POST"><input type="text" name="message" />'
26 . '<input type="submit" /></form><hr/><ul>'
27 2 . (join '' => map { '<li>' . $_ . '</li>' } $self->get_messages)
28 . '</ul></body></html>'
29 }
30  
31 1 ▶ sub process_post {
Subroutine process_post: called CC=1 SCAR=0.0
32 1 my $self = shift;
33 1 $self->save_message( $self->request->param('message') );
34 1 $self->response->header('Location' => '/');
35 1 return \301;
36 }
37  
38 }
39  
40 1 Web::Machine->new( resource => 'YAPC::NA::2012::Example030::Resource' )->to_app;
« examples/hello-world/app.psgi ↑ Summary examples/yapc-talk-examples/100-add-caching.psgi »