blib/lib/Ukigumo/Server.pm

filter: Statementstmt 43.2% 32 / 74 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 66.6% 10 / 15 Podpod 20.0% 1 / 5 totaltotal 29.6% 43 / 145 CC 21 SCAR 33.2
CC
21
Cov
28%
config
56.0
dbh
42.0
dbdriver
30.0
CRAP 27.6
↑ Summary blib/lib/Ukigumo/Server/Web.pm »
1 package Ukigumo::Server;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use version; our $VERSION = version->declare('v2.1.3');
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use parent qw(Amon2);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use Ukigumo::Server::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 __PACKAGE__->load_plugins(qw(ShareDir));
16  
17 sub config {
18 0 ▶ my ($c, $conf) = @_;
Subroutine config: not called CC=7 SCAR=40.3
Pod documented
19 0 ▶ state $config = $conf || do {
Condition0%0/3
$conf || do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf || do { my $env = $c->mode_name || 'development'; my $config_base = 'File::Spec'->catdir($c->base_dir, 'config'); $config_base = 'File::Spec'->catdir($c->share_dir, 'config') unless -d $config_base; my $fname = 'File::Spec'->catfile($config_base, "$env.pl"); my $config = do $fname; Carp::croak("${fname}: $@") if $@; Carp::croak("${fname}: $!") unless defined $config; unless (ref $config eq 'HASH') { Carp::croak("$fname does not return HashRef."); } ; $config }
$conf do { my $env = $c->mode_name || 'development'; my $config_base = 'File::Spec'->catdir($c->base_dir, 'config'); $config_base = 'File::Spec'->catdir($c->share_dir, 'config') unless -d $config_base; my $fname = 'File::Spec'->catfile($config_base, "$env.pl"); my $config = do $fname; Carp::croak("${fname}: $@") if $@; Carp::croak("${fname}: $!") unless defined $config; unless (ref $config eq 'HASH') { Carp::croak("$fname does not return HashRef."); } ; $config }
Truth table0%0/3
A || B
A= $confB= do { my $env = $c->mode_name || 'development'; my $config_base = 'File::Spec'->catdir($c->base_dir, 'config'); $config_base = 'File::Spec'->catdir($c->share_dir, 'config') unless -d $config_base; my $fname = 'File::Spec'->catfile($config_base, "$env.pl"); my $config = do $fname; Carp::croak("${fname}: $@") if $@; Carp::croak("${fname}: $!") unless defined $config; unless (ref $config eq 'HASH') { Carp::croak("$fname does not return HashRef."); } ; $config }
ABresult
1X1
011
000
20 0 ▶ my $env = $c->mode_name || 'development';
Condition0%0/2
$c->mode_name || 'development'
l!l
00
MC/DC0%0/1
$c->mode_name || 'development'
$c->mode_name
Truth table0%0/2
A
A= $c->mode_name
Aresult
11
00
21 0 my $config_base = File::Spec->catdir($c->base_dir, 'config'); # backward compatible
22 0 ▶ $config_base = File::Spec->catdir($c->share_dir, 'config') unless -d $config_base;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $config_base 0 0 0
23 0 my $fname = File::Spec->catfile($config_base, "${env}.pl");
24 0 my $config = do $fname;
25 0 ▶ Carp::croak("$fname: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
26 0 ▶ Carp::croak("$fname: $!") unless defined $config;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config 0 0 0
27 0 ▶ unless ( ref($config) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $config eq "HASH") 0 0 0
28 0 Carp::croak("$fname does not return HashRef.");
29 }
30 0 $config;
31 };
32 }
33  
34 sub dbh {
35 0 ▶ my $self = shift;
Subroutine dbh: not called CC=6 SCAR=37.4
Pod undocumented
36  
37 0 ▶ $self->{dbh} ||= do {
Condition0%0/3
$self->{"dbh"} ||= do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dbh"} ||= do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; $conf->[3]{"RaiseError"} = 1; $conf->[3]{"sqlite_unicode"} = 1 if $self->dbdriver eq "sqlite"; $conf->[3]{"mysql_enable_utf8"} = 1 if $self->dbdriver eq "mysql"; "DBI"->connect(@$conf) or die $DBI::errstr }
$self->{"dbh"} do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; $conf->[3]{"RaiseError"} = 1; $conf->[3]{"sqlite_unicode"} = 1 if $self->dbdriver eq "sqlite"; $conf->[3]{"mysql_enable_utf8"} = 1 if $self->dbdriver eq "mysql"; "DBI"->connect(@$conf) or die $DBI::errstr }
Truth table0%0/3
A ||= B
A= $self->{"dbh"}B= do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; $conf->[3]{"RaiseError"} = 1; $conf->[3]{"sqlite_unicode"} = 1 if $self->dbdriver eq "sqlite"; $conf->[3]{"mysql_enable_utf8"} = 1 if $self->dbdriver eq "mysql"; "DBI"->connect(@$conf) or die $DBI::errstr }
ABresult
1X1
011
000
38 0 ▶ my $conf = $self->config->{DBI} or die "Missing configuration for DBI";
Branch: 1 branch
BranchTrueFalseTotal
my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI" 0 0 0
39 0 $conf->[3]->{RaiseError} = 1;
40 0 ▶ $conf->[3]->{sqlite_unicode} = 1 if $self->dbdriver eq 'sqlite';
Branch: 1 branch
BranchTrueFalseTotal
if $self->dbdriver eq "sqlite" 0 0 0
41 0 ▶ $conf->[3]->{mysql_enable_utf8} = 1 if $self->dbdriver eq 'mysql';
Branch: 1 branch
BranchTrueFalseTotal
if $self->dbdriver eq "mysql" 0 0 0
42 0 ▶ DBI->connect(@$conf) or die $DBI::errstr;
Branch: 1 branch
BranchTrueFalseTotal
"DBI"->connect(@$conf) or die $DBI::errstr 0 0 0
43 };
44 }
45  
46 sub db {
47 0 ▶ my $self = shift;
Subroutine db: not called CC=2 SCAR=17.9
Pod undocumented
48 0 ▶ $self->{db} ||= Ukigumo::Server::DB->new(dbh => $self->dbh);
Condition0%0/3
$self->{"db"} ||= "Ukigumo::Server::DB"->new("dbh", $self->dbh)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"db"} ||= "Ukigumo::Server::DB"->new("dbh", $self->dbh)
$self->{"db"} "Ukigumo::Server::DB"->new("dbh", $self->dbh)
Truth table0%0/3
A ||= B
A= $self->{"db"}B= "Ukigumo::Server::DB"->new("dbh", $self->dbh)
ABresult
1X1
011
000
49 }
50  
51 sub dbdriver {
52 0 ▶ my $self = shift;
Subroutine dbdriver: not called CC=5 SCAR=34.0
Pod undocumented
53  
54 0 ▶ $self->{dbdriver} ||= do {
Condition0%0/3
$self->{"dbdriver"} ||= do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dbdriver"} ||= do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; my $dsn0 = $conf->[0]; my $db = $dsn0 =~ /:mysql:/ ? "MySQL" : ($dsn0 =~ /:Pg:/ ? "PostgreSQL" : do { my($d) = $dsn0 =~ /dbi:(.*?):/; $d }); lc $db }
$self->{"dbdriver"} do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; my $dsn0 = $conf->[0]; my $db = $dsn0 =~ /:mysql:/ ? "MySQL" : ($dsn0 =~ /:Pg:/ ? "PostgreSQL" : do { my($d) = $dsn0 =~ /dbi:(.*?):/; $d }); lc $db }
Truth table0%0/3
A ||= B
A= $self->{"dbdriver"}B= do { my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI"; my $dsn0 = $conf->[0]; my $db = $dsn0 =~ /:mysql:/ ? "MySQL" : ($dsn0 =~ /:Pg:/ ? "PostgreSQL" : do { my($d) = $dsn0 =~ /dbi:(.*?):/; $d }); lc $db }
ABresult
1X1
011
000
55 0 ▶ my $conf = $self->config->{DBI} or die "Missing configuration for DBI";
Branch: 1 branch
BranchTrueFalseTotal
my $conf = $self->config->{"DBI"} or die "Missing configuration for DBI" 0 0 0
56 0 my $dsn0 = $conf->[0];
57 my $db
58 = $dsn0 =~ /:mysql:/ ? 'MySQL'
59 : $dsn0 =~ /:Pg:/ ? 'PostgreSQL'
60 0 ▶ : do { my ($d) = $dsn0 =~ /dbi:(.*?):/; $d };
Branch: 2 branches
BranchTrueFalseTotal
$dsn0 =~ /:mysql:/ ? : 0 0 0
$dsn0 =~ /:Pg:/ ? : 0 0 0
61 0 lc $db;
62 };
63 }
64  
65 sub setup_schema {
66 0 ▶ my $self = shift;
Subroutine setup_schema: not called CC=5 SCAR=34.0
Pod undocumented
67 0 my $f = lc $self->dbdriver . '.sql';
68 0 my $fname = File::Spec->catfile($self->share_dir , 'sql', $f);
69 0 ▶ unless (-f $fname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $fname) 0 0 0
70 # Resolve real share_dir. User himself might create 'share/' dir in current directory.
71 0 my $real_share = File::ShareDir::dist_dir('Ukigumo-Server');
72 0 $fname = File::Spec->catfile($real_share, 'sql', $f);
73 }
74 0 my $schema = do {
75 0 local $/;
76 0 ▶ open my $fh, '<', $fname or die "Cannot open $fname: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fname or die "Cannot open ${fname}: $!" 0 0 0
77 <$fh>
78 0 };
79 0 for my $code (split /;/, $schema) {
80 0 ▶ next if $code =~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /^$/ 0 0 0
81 0 $self->dbh->do( $code );
82 }
83 }
84  
85 13 1;
86 __END__
87  
88 =encoding utf-8
89  
90 =head1 NAME
91  
92 Ukigumo::Server - Testing report storage Server
93  
94 =head1 SYNOPSIS
95  
96 % ukigumo-server
97  
98 =head1 DESCRIPTION
99  
100 Ukigumo::Server is testing report storage server. You can use this server for Continious Testing.
101  
102 =begin html
103  
104 <img src="https://dl.dropboxusercontent.com/u/14832699/Ukigumo-Server-Top.png" alt="Screen shot">
105  
106 =end html
107  
108 =head1 INSTALLATION
109  
110 % cpanm Ukigumo::Server
111 % ukigumo-server
112 ukigumo-server starts listen on 0:2828
113  
114 Or you can use git repo instead of C<< cpanm Ukigumo::Server >> for launching L<Ukigumo::Server>.
115  
116 % git clone git@github.com:ukigumo/Ukigumo-Server.git .
117 # install carton to your system
118 % curl -L http://cpanmin.us | perl - Carton
119 # And setup the depended modules.
120 % carton install
121 # Then, run the http server!
122 % carton exec perl local/bin/ukigumo-server
123  
124 =head1 SEE ALSO
125  
126 L<ukigumo-server>
127  
128 =head1 LICENSE
129  
130 Copyright (C) tokuhirom.
131  
132 This library is free software; you can redistribute it and/or modify
133 it under the same terms as Perl itself.
134  
135 =head1 AUTHOR
136  
137 tokuhirom E<lt>tokuhirom@gmail.comE<gt>
138  
139 =cut
140  
↑ Summary blib/lib/Ukigumo/Server/Web.pm »