Module/Build/Service.pm

filter: Statementstmt 40.7% 31 / 76 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.1% 8 / 21 Podpod n/a totaltotal 35.4% 39 / 110 CC 6 SCAR 13.3
CC
6
Cov
36%
check_dir
12.0
__wrapper
6.0
__ANON__
6.0
CRAP 3.8
« Module/Build/Service/slapd.pm ↑ Summary Module/Build/Service/Base.pm »
1 package Module::Build::Service;
2 {
3 1 $Module::Build::Service::VERSION = '0.91';
4 }
5 # ABSTRACT: Manage services necessary for automated or interactive testing
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Class::Load qw{load_class};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Path qw{make_path remove_tree};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Spec qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Log::Any qw{$log};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base qw{Module::Build};
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub check_dir () {
Subroutine check_dir: not called CC=3 SCAR=24.8
17 0 $log->tracef ("Creating directory %s", $_);
18 0 ▶ -d $_ or make_path ($_) or die "Couldn't create directory $_\n";
Branch: 1 branch
BranchTrueFalseTotal
-d $_ or make_path($_) or die "Couldn't create directory $_\n" 0 0 0
Condition0%0/3
-d $_ or make_path($_)
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $_ or make_path($_)
-d $_ make_path($_)
Truth table0%0/3
A or B
A= -d $_B= make_path($_)
ABresult
1X1
011
000
19 }
20  
21 1 __PACKAGE__->add_property (services => default => []);
22 __PACKAGE__->add_property (mbs_data_dir =>
23 check => \&check_dir,
24 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 $log->tracef ("Defaulting data directory");
26 0 local $_ = File::Spec->rel2abs(File::Spec->catdir ("_build", "mbs", "data"));
27 0 check_dir;
28 0 $_;
29 1 });
30 __PACKAGE__->add_property (mbs_log_dir =>
31 check => \&check_dir,
32 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 $log->tracef ("Defaulting log directory");
34 0 local $_ = File::Spec->rel2abs(File::Spec->catdir ("_build", "mbs", "log"));
35 0 check_dir;
36 0 $_;
37 1 });
38 __PACKAGE__->add_property (mbs_socket_dir =>
39 check => \&check_dir,
40 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 $log->tracef ("Defaulting socket directory");
42 0 local $_ = File::Spec->rel2abs(File::Spec->catdir ("_build", "mbs", "socket"));
43 0 check_dir;
44 0 $_;
45 1 });
46  
47  
48 0 ▶sub ACTION_test {
Subroutine ACTION_test: not called CC=1 SCAR=6.9
49 0 my ($self, @args) = @_;
50 0 $self->__wrapper ("SUPER::ACTION_test", @args);
51 }
52  
53  
54 0 ▶sub ACTION_interact {
Subroutine ACTION_interact: not called CC=1 SCAR=6.9
55 0 my ($self, @args) = @_;
56 0 $self->__wrapper ("interact", @args);
57 }
58  
59 0 ▶sub interact {
Subroutine interact: not called CC=1 SCAR=6.9
60 0 print STDERR "Press enter to continue";
61 0 my $junk = <STDIN>;
62 }
63  
64 # __wrapper is the heart of the routines we expose. It will start
65 # required and/or recommended services before executing the named method
66 # that is handed to it as its sole argument. When that method returns,
67 # __wrapper shuts down all the running services and leaves.
68  
69 0 ▶sub __wrapper {
Subroutine __wrapper: not called CC=2 SCAR=17.9
70 0 my ($self, $method, @args) = @_;
71  
72 0 $log->tracef ("Wrapping %s", $method);
73  
74 0 my ($failure, @running);
75  
76 0 $log->trace ("Starting up services");
77 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 @running = map {
79 0 my ($name, $required, %args) = @{$_};
80 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 my $class = "Module::Build::Service::$name";
82 0 $log->tracef ("Attempting to load %s", $name);
83 0 load_class $class;
84 0 $log->tracef ("Attempting to instantiate %s", $name);
85 0 $class->new (_builder => $self, %args);
86 0 ▶ } catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
87 0 $log->errorf ("Failed to start %s: %s", $name, $_);
88 0 ▶ $required and die "Don't know how to handle required service $name: $_";
Branch: 1 branch
BranchTrueFalseTotal
$required and die "Don't know how to handle required service ${name}: $_" 0 0 0
89 }
90 0 } @{$self->services};
91 0 $log->tracef ("Running %s", $method);
92 0 $self->$method (@args);
93 0 $log->tracef ("Done with %s", $method);
94 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 $log->errorf ("Failure starting services: %s", $_);
96 0 $failure = $_;
97 0 ▶ } finally {
Subroutine __ANON__: not called CC=2 SCAR=17.9
98 0 $log->trace ("Shutting down services");
99 0 ▶ pop @running while @running;
Branch: 1 branch
BranchTrueFalseTotal
@running and do { pop @running } 0 0 0
100 0 };
101  
102 0 ▶ die $failure if ($failure);
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 0 0
103 }
104  
105 1 1;
106  
107 __END__
« Module/Build/Service/slapd.pm ↑ Summary Module/Build/Service/Base.pm »