Mojito/Middleware.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran n/a Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 43 CC 1 SCAR 6.9
CC
1
Cov
0%
call
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use strictures 1;
2 package Mojito::Middleware;
3 $Mojito::Middleware::VERSION = '0.25';
4 use parent qw(Plack::Middleware);
5 use Plack::Util::Accessor qw/config/;
6 use Mojito;
7 use DateTime::TimeZone;
8  
9 =head1 Name
10  
11 Mojito::Middleware - gather some environment variables
12  
13 =cut
14  
15 # Let's gather some stuff from the environment
16 # that we'd like to have access to in our app.
17 sub call {
18 my ( $self, $env ) = @_;
19  
20 my $config = $self->config;
21 my $base_url = $env->{SCRIPT_NAME} || '/';
22 $base_url =~ s/([^\/])$/$1\//;
23 $config->{base_url} = $base_url;
24 my @my_env = qw/REMOTE_USER PATH_INFO URI_REQUEST HTTP_REFERER HTTP_HOST/;
25 @{$config}{qw/username PATH_INFO URI_REQUEST HTTP_REFERER HTTP_HOST/} = @{$env}{@my_env};
26 $config->{local_timezone} ||= DateTime::TimeZone->new(name => 'local')->name;
27 # TODO?: Just use a hash instead of an object
28 $env->{"mojito"} = Mojito->new(
29 base_url => $base_url,
30 config => $config,
31 );
32  
33 $self->app->($env);
34 }
35  
36 1;