File Coverage

blib/lib/Puncheur/Lite.pm
Criterion Covered Total %
statement 82 82 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 19 19 100.0
pod n/a
total 103 106 97.1


line stmt bran cond sub pod time code
1             package Puncheur::Lite;
2 1     1   19 use 5.010;
  1         2  
  1         30  
3 1     1   4 use strict;
  1         1  
  1         20  
4 1     1   3 use warnings;
  1         1  
  1         24  
5              
6 1     1   3 use File::Spec;
  1         1  
  1         18  
7 1     1   403 use Data::Section::Simple ();
  1         455  
  1         16  
8              
9 1     1   337 use Puncheur ();
  1         3  
  1         22  
10 1     1   432 use Puncheur::Dispatcher::Lite ();
  1         3  
  1         36  
11              
12             sub import {
13 1     1   2 my ($class) = @_;
14 1         2 my $caller = caller;
15              
16             {
17 1     1   5 no strict 'refs';
  1         2  
  1         51  
  1         2  
18 1         1 push @{"$caller\::ISA"}, 'Puncheur';
  1         13  
19              
20 1         6 $caller->load_plugin('HandleStatic');
21 1         3 my $to_psgi = $caller->can('to_psgi');
22              
23 1     1   4 no warnings 'redefine';
  1         0  
  1         51  
24 1         3 *{"$caller\::to_psgi"} = sub {
25 1     1   3 use strict 'refs';
  1         2  
  1         38  
26 1     1   7 my $app = $to_psgi->(@_);
27             {
28 1     1   3 no strict 'refs';
  1         2  
  1         37  
  1         2  
29 1 50       1 if (my @middlewares = @{"$caller\::_MIDDLEWARES"}) {
  1         8  
30 1     1   4 use strict 'refs';
  1         2  
  1         166  
31 1         2 for my $middleware (@middlewares) {
32 1         2 my ($klass, $args) = @$middleware;
33 1         5 $klass = Plack::Util::load_class($klass, 'Plack::Middleware');
34 1         44 $app = $klass->wrap($app, %$args);
35             }
36             }
37             }
38 1         1013 $app;
39 1         27 };
40              
41 1         3 *{"$caller\::enable_middleware"} = sub {
42 1     1   2 my ($klass, %args) = @_;
43 1         2 push @{"$caller\::_MIDDLEWARES"}, [$klass, \%args];
  1         9  
44 1         2 };
45 1         4 *{"$caller\::enable_session"} = sub {
46 1     1   5 use strict 'refs';
  1         1  
  1         219  
47 1     1   2 my (%args) = @_;
48 1   33     4 $args{state} ||= do {
49 1         430 require Plack::Session::State::Cookie;
50 1         3678 Plack::Session::State::Cookie->new(httponly => 1); # for security
51             };
52 1         437 require Plack::Middleware::Session;
53              
54 1         2072 my $func = $caller->can('enable_middleware');
55 1         6 $func->('Plack::Middleware::Session', %args);
56 1         2 };
57             }
58              
59             my $tmpl = sub {
60 1     1   6 File::Spec->catdir($caller->asset_dir, 'tmpl');
61 1         2 };
62 1     1   13 $caller->setting(
63 1         7 template_dir => [sub {Data::Section::Simple->new($caller)->get_data_section}, $tmpl],
64             );
65              
66 1         9 strict->import;
67 1         6 warnings->import;
68 1         6 utf8->import;
69 1         5 require feature;
70 1         73 feature->import(':5.10');
71              
72 1         1 goto do { Puncheur::Dispatcher::Lite->can('import') };
  1         11  
73             }
74              
75             1;