Module/Build/Service/postgresql.pm

filter: Statementstmt 34.7% 24 / 69 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 35.7% 5 / 14 Podpod 100% 2 / 2 totaltotal 26.9% 31 / 115 CC 13 SCAR 24.9
CC
13
Cov
26%
_build_bindir
30.0
start_service
20.0
_build_data
12.0
CRAP 12.0
↑ Summary Module/Build/Service/Fork.pm »
1 package Module::Build::Service::postgresql;
2 {
3 1 $Module::Build::Service::postgresql::VERSION = '0.91';
4 }
5 # ABSTRACT: Service implementation for postgresql
6  
7 1 ▶use File::Path qw{make_path remove_tree};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Log::Any qw{$log};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 extends 'Module::Build::Service::Base';
13  
14  
15 1 has 'bindir' => (is => 'lazy');
16 0 ▶sub _build_bindir {
Subroutine _build_bindir: not called CC=5 SCAR=34.0
17 0 my ($self) = @_;
18 0 for my $prefix ("/usr/lib/postgresql", "/usr/local/lib/postgresql") {
19 0 my $dir = File::Spec->catdir ($prefix, $self->version, "bin");
20 0 $log->tracef ("Checking %s for binaries", $dir);
21 0 ▶ if (-e File::Spec->catfile ($dir, "pg_ctl") and -e File::Spec->catfile ($dir, "createdb") and -e File::Spec->catfile ($dir, "pg_dumpall")) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "File::Spec"->catfile($dir, "pg_ctl") and -e "File::Spec"->catfile($dir, "createdb") and -e "File::Spec"->catfile($dir, "pg_dumpall")) 0 0 0
Condition0%0/6
-e "File::Spec"->catfile($dir, "pg_ctl") and -e "File::Spec"->catfile($dir, "createdb") and -e "File::Spec"->catfile($dir, "pg_dumpall")
!ll&&!rl&&r
000
-e "File::Spec"->catfile($dir, "pg_ctl") and -e "File::Spec"->catfile($dir, "createdb")
!ll&&!rl&&r
000
MC/DC0%0/3
-e "File::Spec"->catfile($dir, "pg_ctl") and -e "File::Spec"->catfile($dir, "createdb") and -e "File::Spec"->catfile($dir, "pg_dumpall")
-e "File::Spec"->catfile($dir, "pg_ctl") -e "File::Spec"->catfile($dir, "createdb") -e "File::Spec"->catfile($dir, "pg_dumpall")
Truth table0%0/4
A and B and C
A= -e "File::Spec"->catfile($dir, "pg_ctl")B= -e "File::Spec"->catfile($dir, "createdb")C= -e "File::Spec"->catfile($dir, "pg_dumpall")
ABCresult
0XX0
10X0
1100
1111
22 0 $log->tracef ("Returning %s as binary directory", $dir);
23 0 return $dir;
24 }
25 }
26 0 die "Couldn't find postgresql binaries";
27 }
28  
29  
30 1 has 'data' => (is => 'lazy');
31 0 ▶sub _build_data {
Subroutine _build_data: not called CC=3 SCAR=24.8
32 0 my ($self) = @_;
33 0 my $dir = File::Spec->catdir ($self->_builder->mbs_data_dir, 'postgresql');
34 0 ▶ -d $dir or make_path ($dir) or die "Couldn't create data directory " . $dir;
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or make_path($dir) or die q[Couldn't create data directory ] . $dir 0 0 0
Condition0%0/3
-d $dir or make_path($dir)
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $dir or make_path($dir)
-d $dir make_path($dir)
Truth table0%0/3
A or B
A= -d $dirB= make_path($dir)
ABresult
1X1
011
000
35 0 $dir;
36 }
37  
38  
39 1 has 'dump' => (is => 'lazy');
40 0 ▶sub _build_dump {
Subroutine _build_dump: not called CC=1 SCAR=6.9
41 0 my ($self) = @_;
42 0 File::Spec->catfile ($self->_builder->mbs_log_dir, 'postgresql.sql');
43 }
44  
45  
46 has 'service' => (is => 'ro',
47 0 ▶ isa => sub {!defined $_[0] or ref $_[0] eq "ARRAY"},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] or ref $_[0] eq "ARRAY" 0 0 0
48 1 predicate => 'has_service');
49  
50  
51 1 has 'version' => (is => 'lazy');
52  
53 0 ▶sub _build_version {
Subroutine _build_version: not called CC=2 SCAR=17.9
54 0 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 (my $version = qx/psql -V/) =~ s/^psql \(PostgreSQL\) (\d+\.\d+)(?:\.|beta|rc)\d+.+/$1/s;
56 0 ▶ die "Couldn't not figure out postgresql version" unless $version;
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 0 0
57 0 $version;
58 }
59  
60  
61 0 ▶sub _bin {
Subroutine _bin: not called CC=1 SCAR=6.9
62 0 my ($self, $bin) = @_;
63 0 File::Spec->catfile ($self->bindir, $bin);
64 }
65  
66  
67 0 ▶sub start_service {
Subroutine start_service: not called CC=4 SCAR=30.0
Pod documented
68 0 my ($self) = @_;
69 0 $log->debug ("postgresql service initializing");
70 0 $self->run_process ($self->_bin ("pg_ctl"), "init", "-s", "-D", $self->data, "-o", "-A trust");
71 0 $log->debug ("postgresql service starting");
72 0 ▶ my $logfile = $self->log =~ m,^/, ? $self->log : File::Spec->catfile ($self->_builder->mbs_log_dir, $self->log);
Branch: 1 branch
BranchTrueFalseTotal
$self->log =~ m[^/] ? : 0 0 0
73 0 $self->run_process ($self->_bin ("pg_ctl"), "start", "-s", "-w", "-D", $self->data, "-l", $logfile, "-o", "-h '' -F -k " . $self->data);
74 0 ▶ if ($self->has_service) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_service) 0 0 0
75 0 $log->debug ("Writing service file");
76 0 $ENV{PGSYSCONFDIR} = $self->data;
77 write_file "$ENV{PGSYSCONFDIR}/pg_service.conf", map {
78 0 ▶ my ($service, $database) = ref $_ ? @{$_} : ($_, $_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
79 0 $self->run_process ($self->_bin ("createdb"), "-h", $self->data, $database);
80 0 sprintf "[%s]\ndbname=%s\nhost=%s\n", $service, $database, $self->data;
81 0 } @{$self->service};
82 }
83 0 warn "Postgresql instance available using '-h " . $self->data . "'\n";
84 }
85  
86  
87 0 ▶sub stop_service {
Subroutine stop_service: not called CC=2 SCAR=17.9
Pod documented
88 0 my ($self) = @_;
89 0 ▶ if ($self->dump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dump) 0 0 0
90 0 $log->trace ("Dumping sql data");
91 0 $self->run_process ($self->_bin ("pg_dumpall"), "-h", $self->data, "-f", $self->dump);
92 }
93 0 $log->debug ("postgresql service stopping");
94 0 $self->run_process ($self->_bin ("pg_ctl"), "stop", "-m", "immediate", "-s", "-D", $self->data);
95 0 $log->debug ("Cleaning up");
96 0 remove_tree ($self->data);
97 }
98  
99 1 1;
100  
101  
102 __END__
↑ Summary Module/Build/Service/Fork.pm »