| 1 | package Ukigumo::Server; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use version; our $VERSION = version->declare('v2.1.4'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use parent qw(Amon2); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use File::ShareDir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | use Ukigumo::Server::DB; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | __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 {
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
}
| |||||||||||||||||||||
| 20 | 0 | ▶ | my $env = $c->mode_name || 'development'; | ||||||||||||||||||
|
Condition0%0/2
$c->mode_name || 'development'
MC/DC0%0/1
$c->mode_name || 'development'
$c->mode_name
Truth table0%0/2
A
A= $c->mode_name
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 26 | 0 | ▶ | Carp::croak("$fname: $!") unless defined $config; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 0 | ▶ | unless ( ref($config) eq 'HASH' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 {
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
}
| |||||||||||||||||||||
| 38 | 0 | ▶ | my $conf = $self->config->{DBI} or die "Missing configuration for DBI"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | $conf->[3]->{RaiseError} = 1; | |||||||||||||||||||
| 40 | 0 | ▶ | $conf->[3]->{sqlite_unicode} = 1 if $self->dbdriver eq 'sqlite'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | ▶ | $conf->[3]->{mysql_enable_utf8} = 1 if $self->dbdriver eq 'mysql'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | ▶ | DBI->connect(@$conf) or die $DBI::errstr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||
| 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 {
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
}
| |||||||||||||||||||||
| 55 | 0 | ▶ | my $conf = $self->config->{DBI} or die "Missing configuration for DBI"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 77 | <$fh> | ||||||||||||||||||||
| 78 | 0 | }; | |||||||||||||||||||
| 79 | 0 | for my $code (split /;/, $schema) { | |||||||||||||||||||
| 80 | 0 | ▶ | next if $code =~ /^$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | $self->dbh->do( $code ); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 2 | 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 | |||||||||||||||||||||