blib/lib/Ukigumo/Server/Web.pm

filter: Statementstmt 65.2% 30 / 46 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 62.5% 10 / 16 Podpod n/a totaltotal 47.6% 40 / 84 CC 10 SCAR 29.0
CC
10
Cov
47%
lang
56.0
create_view
12.0
duration
6.0
CRAP 18.2
« blib/lib/Ukigumo/Server.pm ↑ Summary blib/lib/Ukigumo/Server/API/Dispatcher.pm »
1 package Ukigumo::Server::Web;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use parent qw/Ukigumo::Server Amon2::Web/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use Ukigumo::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # dispatcher
11 12 ▶use Ukigumo::Server::Web::Dispatcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 sub dispatch {
13 0 ▶ my $c = shift;
Subroutine dispatch: not called CC=1 SCAR=6.9
14 0 return Ukigumo::Server::Web::Dispatcher->dispatch($c)
15 or die "response is not generated";
16 }
17  
18 # setup view class
19 sub create_view {
20 0 ▶ state $view = do {
Subroutine create_view: not called CC=3 SCAR=24.8
21 0 ▶ my $view_conf = __PACKAGE__->config->{'Text::Xslate'} || +{};
Condition0%0/2
__PACKAGE__->config->{'Text::Xslate'} || {}
l!l
00
MC/DC0%0/1
__PACKAGE__->config->{'Text::Xslate'} || {}
__PACKAGE__->config->{'Text::Xslate'}
Truth table0%0/2
A
A= __PACKAGE__->config->{'Text::Xslate'}
Aresult
11
00
22 0 ▶ unless (exists $view_conf->{path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $view_conf->{"path"}) 0 0 0
23 0 $view_conf->{path} = [ File::Spec->catdir(__PACKAGE__->share_dir(), 'tmpl') ];
24 }
25 Text::Xslate->new(+{
26 0 'syntax' => 'Kolon',
27 'module' => [ 'Ukigumo::Helper', 'Text::Xslate::Bridge::Star', 'Ukigumo::Server::Web::ViewFunctions' ],
28 %$view_conf
29 });
30 };
31 }
32  
33 __PACKAGE__->load_plugins(
34 'Web::JSON',
35 'Web::PlackSession',
36 'Web::CSRFDefender',
37 );
38  
39 # for your security
40 __PACKAGE__->add_trigger(
41 AFTER_DISPATCH => sub {
42 my ( $c, $res ) = @_;
43 $res->header( 'X-Content-Type-Options' => 'nosniff' );
44 },
45 );
46  
47 12 ▶use Ukigumo::Server::L10N;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 0 ▶sub loc { shift->l10n->maketext(@_) }
Subroutine loc: not called CC=1 SCAR=6.9
50  
51 __PACKAGE__->add_trigger(
52 BEFORE_DISPATCH => sub {
53 my $c = shift;
54  
55 if ( my $lang = $c->req->param('lang') ) {
56 return $c->show_error("Unknown language: $lang")
57 if $lang !~ /^(?:en|ja)$/;
58 $c->session->set( lang => $lang );
59 }
60  
61 return undef;
62 },
63 );
64  
65 {
66 my %langs = (
67 ja => Ukigumo::Server::L10N->get_handle('ja'),
68 en => Ukigumo::Server::L10N->get_handle('en'),
69 );
70  
71 sub lang {
72 0 ▶ my ($c) = @_;
Subroutine lang: not called CC=7 SCAR=40.3
73 0 ▶ return 'ja' if ( $c->session->get('lang') || 'en' ) eq 'ja';
Branch: 1 branch
BranchTrueFalseTotal
if ($c->session->get("lang") || "en") eq "ja" 0 0 0
Condition0%0/2
$c->session->get('lang') || 'en'
l!l
00
MC/DC0%0/1
$c->session->get('lang') || 'en'
$c->session->get('lang')
Truth table0%0/2
A
A= $c->session->get('lang')
Aresult
11
00
74 0 ▶ return 'ja' if ( $c->req->param('lang') || 'en' ) eq 'ja';
Branch: 1 branch
BranchTrueFalseTotal
if ($c->req->param("lang") || "en") eq "ja" 0 0 0
Condition0%0/2
$c->req->param('lang') || 'en'
l!l
00
MC/DC0%0/1
$c->req->param('lang') || 'en'
$c->req->param('lang')
Truth table0%0/2
A
A= $c->req->param('lang')
Aresult
11
00
75 0 ▶ return 'en' if ( $c->req->header('Accept-Language') || 'ja' ) =~ /en/;
Branch: 1 branch
BranchTrueFalseTotal
if ($c->req->header("Accept-Language") || "ja") =~ /en/ 0 0 0
Condition0%0/2
$c->req->header('Accept-Language') || 'ja'
l!l
00
MC/DC0%0/1
$c->req->header('Accept-Language') || 'ja'
$c->req->header('Accept-Language')
Truth table0%0/2
A
A= $c->req->header('Accept-Language')
Aresult
11
00
76 0 return 'en';
77 }
78  
79 sub l10n {
80 0 ▶ my ($c) = @_;
Subroutine l10n: not called CC=1 SCAR=6.9
81 0 return $langs{ $c->lang };
82 }
83  
84 12 ▶ use Time::Duration ();
Subroutine BEGIN: called CC=1 SCAR=0.0
85 12 ▶ use Time::Duration::ja ();
Subroutine BEGIN: called CC=1 SCAR=0.0
86 sub duration {
87 0 ▶ shift->lang eq 'ja' ? 'Time::Duration::ja' : 'Time::Duration';
Subroutine duration: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->lang eq 'ja' ? : 0 0 0
88 }
89 }
90  
91  
92  
93 1;
« blib/lib/Ukigumo/Server.pm ↑ Summary blib/lib/Ukigumo/Server/API/Dispatcher.pm »