blib/lib/Ukigumo/Server/Command/Branch.pm

filter: Statementstmt 32.7% 18 / 55 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 5 totaltotal 30.3% 24 / 79 CC 5 SCAR 19.4
CC
5
Cov
29%
list
20.0
find_or_create
6.0
find
2.0
CRAP 6.9
« blib/lib/Ukigumo/Server/Command/Report.pm ↑ Summary blib/lib/Ukigumo/Server/Web/Dispatcher.pm »
1 package Ukigumo::Server::Command::Branch;
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 utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Amon2::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Data::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub find_or_create {
11 0 ▶ my $class = shift;
Subroutine find_or_create: not called CC=2 SCAR=17.9
Pod undocumented
12 0 state $rule = Data::Validator->new(
13 project => { isa => 'Str' },
14 branch => { isa => 'Str' },
15 );
16 0 my $args = $rule->validate(@_);
17  
18 0 ▶ my $base_sql = c->dbdriver eq 'mysql' ? 'INSERT IGNORE INTO' : 'INSERT OR IGNORE INTO';
Branch: 1 branch
BranchTrueFalseTotal
c()->dbdriver eq 'mysql' ? : 0 0 0
19 c->db->fast_insert(branch => {
20 project => $args->{project},
21 branch => $args->{branch},
22 0 ctime => time(),
23 }, $base_sql);
24  
25 0 return $class->find(%$args);
26 }
27  
28 sub find {
29 0 ▶ my $class = shift;
Subroutine find: not called CC=1 SCAR=6.9
Pod undocumented
30 0 state $rule = Data::Validator->new(
31 project => { isa => 'Str' },
32 branch => { isa => 'Str' },
33 );
34 0 my $args = $rule->validate(@_);
35  
36 0 local c->db->{suppress_row_objects} = 1;
37 0 return eval { c->db->single(branch => {project => $args->{project}, branch => $args->{branch}})->{branch_id} };
38 }
39  
40 sub lookup {
41 0 ▶ my $class = shift;
Subroutine lookup: not called CC=1 SCAR=6.9
Pod undocumented
42 0 state $rule = Data::Validator->new(
43 branch_id => { isa => 'Int' },
44 );
45 0 my $args = $rule->validate(@_);
46 0 local c->db->{suppress_row_objects} = 1;
47 0 return c->db->single(branch => {branch_id => $args->{branch_id}});
48 }
49  
50 sub delete {
51 0 ▶ my $class = shift;
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
52 0 state $rule = Data::Validator->new(
53 branch_id => { isa => 'Int' },
54 );
55 0 my $args = $rule->validate(@_);
56 0 c->db->delete(branch => {branch_id => $args->{branch_id}});
57 0 c->db->delete(report => {branch_id => $args->{branch_id}});
58 0 return;
59 }
60  
61 sub list {
62 0 ▶ my $class = shift;
Subroutine list: not called CC=4 SCAR=30.0
Pod undocumented
63 0 state $rule = Data::Validator->new(
64 project => { isa => 'Str', optional => 1 },
65 status => { isa => 'ArrayRef', optional => 1 },
66 );
67 0 my $args = $rule->validate(@_);
68  
69 0 my $sql = q{SELECT DISTINCT branch.project, branch.branch, report.report_id, report.status, report.revision, report.ctime, report.elapsed_time_sec
70 FROM branch LEFT JOIN report ON (branch.last_report_id=report.report_id) };
71 0 my @wheres;
72 0 ▶ if (exists $args->{project}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"project"}) 0 0 0
73 0 push @wheres, 'project = :project ';
74 }
75 0 ▶ if (exists $args->{status}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"status"}) 0 0 0
76 0 push @wheres, 'status IN :status ';
77 }
78 0 ▶ $sql .= q{WHERE } . join('AND ', @wheres) if @wheres;
Branch: 1 branch
BranchTrueFalseTotal
if @wheres 0 0 0
79 0 $sql .= q{ORDER BY last_report_id DESC};
80  
81 0 my $itr = c->db->search_named($sql, $args);
82 0 $itr->suppress_object_creation(1);
83  
84 0 [$itr->all];
85 }
86  
87 12 1;
« blib/lib/Ukigumo/Server/Command/Report.pm ↑ Summary blib/lib/Ukigumo/Server/Web/Dispatcher.pm »