eg/lib/My/App.pm

filter: Statementstmt 27.8% 17 / 61 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 5 / 10 Podpod 20.0% 1 / 5 totaltotal 24.4% 23 / 94 CC 8 SCAR 33.7
CC
8
Cov
23%
handler
60.0
index
2.0
view
2.0
CRAP 29.0
↑ Summary blib/lib/DBIx/VersionedSubs.pm »
1 package My::App;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use base 'DBIx::VersionedSubs';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 My::App - Sample base framework implementation
10  
11 =head1 SYNOPSIS
12  
13 =head1 ABSTRACT
14  
15 This is a sample application for you to start from. Together
16 with L<DBIx::VersionedSubs::Server>, it provides a very frugal
17 yet functional environment to evolve more code within your
18 web browser.
19  
20 It provides a basic dispatch mechanism, basic templates
21 and the two functions C<view> and C<save> to create,
22 view, and save functions.
23  
24 The source code is most instructive to be read by you
25 to get an idea of what to do with this framework. I expect that
26 you will want to implement your own handler instead of
27 extending this sample code.
28  
29 =cut
30  
31 0 ▶sub index {
Subroutine index: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my ($cgi,$res) = @_;
33 0 $res->{code} = "200";
34 return +{
35 0 title => 'Hello from ' . __PACKAGE__,
36 body => 'This is a message presented to you by ' . __PACKAGE__,
37 }
38 }
39  
40 0 ▶sub view {
Subroutine view: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my ($cgi,$res) = @_;
42 0 $res->{code} = "200";
43 0 my $sub = $cgi->param('sub');
44 return +{
45 name => $sub,
46 0 'sub' => __PACKAGE__->code_source->{$sub},
47 }
48 }
49  
50 0 ▶sub save {
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($cgi,$res) = @_;
52 0 $res->{code} = "302";
53 0 my $sub = $cgi->param('sub');
54 0 my $code = $cgi->param('code');
55 0 $res->{header}->{Location} = "http://localhost/view?sub=$sub";
56 0 __PACKAGE__->redefine_sub($sub,$code);
57 0 return +{};
58 }
59  
60 0 ▶sub load_template {
Subroutine load_template: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($name,$cgi) = @_;
62 0 return "templates/$name.tmpl";
63 }
64  
65 15 my $t = Template->new();
66 0 ▶sub handler {
Subroutine handler: not called CC=8 SCAR=40.9
Pod documented
67 0 my ($package,$cgi) = @_;
68  
69 0 warn "--- ";
70 0 my ($name,$template);
71 0 $name = "index";
72 0 ▶ if ($cgi->path_info =~ m!^/(\w+)!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgi->path_info =~ m[^/(\w+)]) 0 0 0
73 0 $name = $1
74 };
75 0 ▶ $template = $cgi->param('template') || $name;
Condition0%0/3
$cgi->param('template') || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$cgi->param('template') || $name
$cgi->param('template') $name
Truth table0%0/3
A || B
A= $cgi->param('template')B= $name
ABresult
1X1
011
000
76 0 my $res = {
77 header => {
78 'Content-Type' => 'text/html',
79 },
80 code => 500,
81 message => 'Internal Server Error',
82 template => $template,
83 };
84  
85 0 my $params = do {
86 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
87 0 my $c = __PACKAGE__ . ":\:$name";
88 0 warn "$c()";
89 0 eval { &{$c}($cgi,$res); };
90 };
91 0 ▶ if (my $err = $@ or ! $params) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@ or not $params) 0 0 0
Condition0%0/3
my $err = $@ or not $params
l!l&&r!l&&!r
000
MC/DC0%0/2
my $err = $@ or not $params
my $err = $@ not $params
Truth table0%0/3
A or not(B)
A= my $err = $@B= not $params
ABresult
1X1
011
000
92 0 $params = {
93 error_message => $err,
94 name => $name,
95 template => $template,
96 query => $cgi,
97 };
98 0 $res->{code} = 500;
99 0 $res->{message} = "Internal Server Error";
100 0 $res->{header}->{'Content-Type'} = "text/html";
101 0 $template = 'error';
102 };
103
104 0 print "HTTP/1.0 $res->{code} $res->{message}\r\n";
105 0 for (sort keys %{$res->{header}}) {
106 0 print "$_: " . $res->{header}->{$_} . "\r\n";
107 }
108 0 print "\r\n";
109
110 0 ▶ if (exists $res->{template}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $res->{'template'}) { } 0 0 0
111 0 ▶ $t->process(load_template($template), {
Branch: 1 branch
BranchTrueFalseTotal
$t->process(load_template($template), {"params", $params, "query", $cgi, "namespace", $package}) or die $Template::ERROR 0 0 0
112 params => $params,
113 query => $cgi,
114 namespace => $package
115 }) or die $Template::ERROR;
116 } else {
117 # raw output
118 print $res->{body}
119 0 }
120 }
121  
122 15 1;
↑ Summary blib/lib/DBIx/VersionedSubs.pm »