Middleware/HTTPSession.pm

filter: Statementstmt 100% 57 / 57 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 92.7% 77 / 83 SCAR 16.1
CC
5
Cov
94%
__ANON__
2.5
__ANON__
2.0
__ANON__
2.0
CRAP 5.0
« Middleware/DebugRequest.pm ↑ Summary Middleware/MobileAttribute.pm »
1 package HTTP::Engine::Middleware::HTTPSession;
2 1 ▶use HTTP::Engine::Middleware;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Any::Moose 'X::Types' => [ -declare => [qw/State Store/] ];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use HTTP::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 subtype State,
8 as 'CodeRef';
9 coerce State,
10 from 'Object',
11 via {
12 1 ▶ my $x = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
13 1 ▶ sub { $x }
Subroutine __ANON__: called CC=1 SCAR=0.0
14 1 };
15 coerce State,
16 from 'HashRef',
17 via {
18 2 ▶ my $klass = $_->{class};
Subroutine __ANON__: called CC=2 SCAR=7.0
19 2 ▶ $klass = $klass =~ s/^\+// ? $klass : "HTTP::Session::State::${klass}";
Branch: 1 branch
BranchTrueFalseTotal
$klass =~ s/^\+// ? : 0 2 2
20 2 Any::Moose::load_class($klass);
21 2 my $obj = $klass->new( $_->{args} );
22 2 ▶ sub { $obj };
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 };
24  
25 1 subtype Store,
26 as 'CodeRef';
27 coerce Store,
28 from 'Object',
29 via {
30 1 ▶ my $x = $_;
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 ▶ sub { $x }
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1 };
33 coerce Store,
34 from 'HashRef',
35 via {
36 2 ▶ my $klass = $_->{class};
Subroutine __ANON__: called CC=2 SCAR=7.0
37 2 ▶ $klass = $klass =~ s/^\+// ? $klass : "HTTP::Session::Store::${klass}";
Branch: 1 branch
BranchTrueFalseTotal
$klass =~ s/^\+// ? : 0 2 2
38 2 Any::Moose::load_class($klass);
39 2 my $obj = $klass->new( $_->{args} );
40 2 ▶ sub { $obj };
Subroutine __ANON__: called CC=1 SCAR=0.0
41 1 };
42  
43 1 has 'state' => (
44 is => 'ro',
45 isa => State,
46 coerce => 1,
47 );
48  
49 1 has 'store' => (
50 is => 'ro',
51 isa => Store,
52 coerce => 1,
53 );
54  
55 {
56 1 my $SESSION;
57 my $SELF;
58 1 my $REQ;
59  
60 middleware_method 'session' => sub {
61 1 ▶ $SESSION ||= HTTP::Session->new(
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$SESSION ||= "HTTP::Session"->new("state", $SELF->state->(), "store", $SELF->store->(), "request", $REQ)
l!l&&r!l&&!r
010
MC/DC0%0/2
$SESSION ||= "HTTP::Session"->new("state", $SELF->state->(), "store", $SELF->store->(), "request", $REQ)
$SESSION "HTTP::Session"->new("state", $SELF->state->(), "store", $SELF->store->(), "request", $REQ)
Truth table33%1/3
A ||= B
A= $SESSIONB= "HTTP::Session"->new("state", $SELF->state->(), "store", $SELF->store->(), "request", $REQ)
ABresult
1X1
011
000
62 state => $SELF->state->(),
63 store => $SELF->store->(),
64 request => $REQ,
65 );
66 1 };
67  
68 before_handle {
69 2 ▶ (undef, $SELF, $REQ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
70 2 undef $SESSION;
71 2 $REQ;
72 1 };
73  
74 after_handle {
75 2 ▶ my ($c, $self, $req, $res) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
76 2 ▶ if ($SESSION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SESSION) 1 1 2
77 1 $SESSION->response_filter($res);
78 1 $SESSION->finalize();
79 }
80 2 undef $SESSION;
81 2 undef $SELF;
82 2 undef $REQ;
83 2 $res;
84 1 };
85 }
86  
87 __MIDDLEWARE__
88  
89 1 __END__
90  
91 =head1 NAME
92  
93 HTTP::Engine::Middleware::HTTPSession - session support at middleware layer
94  
95 =head1 SYNOPSIS
96  
97 my $mw = HTTP::Engine::Middleware->new;
98 $mw->install( 'HTTP::Engine::Middleware::HTTPSession' => {
99 state => {
100 class => 'URI',
101 args => {
102 session_id_name => 'foo_sid',
103 },
104 },
105 store => {
106 class => 'Test',
107 args => { },
108 },
109 });
110 HTTP::Engine->new(
111 interface => {
112 module => 'YourFavoriteInterfaceHere',
113 request_handler => $mw->handler( \&handler ),
114 }
115 )->run();
116  
117 =head1 DESCRIPTION
118  
119 This middleware add the session management stuff for your web application
120  
121 =head1 AUTHOR
122  
123 tokuhirom
124  
125 =head1 SEE ALSO
126  
127 L<HTTP::Engine::Middleware>, L<HTTP::Session>
128  
« Middleware/DebugRequest.pm ↑ Summary Middleware/MobileAttribute.pm »