lib/Mite/Config.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 87.5% 7 / 8 Conditioncond 78.5% 11 / 14 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 7 totaltotal 82.0% 87 / 106 CC 10 SCAR 8.6
CC
10
Cov
92%
find_mite_dir
5.0
should_tidy
2.5
make_mite_dir
2.0
CRAP 2.4
« lib/Mite/App.pm ↑ Summary lib/Mite/MakeMaker.pm »
1 115 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 115 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 115 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Mite::Config;
6 115 ▶use Mite::Miteception -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 115 our $AUTHORITY = 'cpan:TOBYINK';
9 115 our $VERSION = '0.013000';
10  
11 115 has mite_dir_name =>
12 is => ro,
13 isa => Str,
14 default => '.mite';
15  
16 has mite_dir =>
17 is => ro,
18 isa => Path,
19 coerce => true,
20 lazy => true,
21 848 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
22 848 my $self = shift;
23 848 ▶ return $self->find_mite_dir ||
Condition100%2/2
$self->find_mite_dir || croak("No @{[$self->mite_dir_name];} directory found.\n")
l!l
22826
MC/DC100%1/1
$self->find_mite_dir || croak("No @{[$self->mite_dir_name];} directory found.\n")
$self->find_mite_dir
Truth table100%2/2
A
A= $self->find_mite_dir
Aresult
11
00
24 826 croak "No @{[$self->mite_dir_name]} directory found.\n";
25 115 };
26  
27 has config_file =>
28 is => ro,
29 isa => Path,
30 coerce => true,
31 lazy => true,
32 847 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 847 my $self = shift;
34 847 return $self->mite_dir->child("config");
35 115 };
36  
37 has data =>
38 is => rw,
39 isa => HashRef,
40 lazy => true,
41 838 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 838 my $self = shift;
43 838 return $self->yaml_load( $self->config_file->slurp_utf8 );
44 115 };
45  
46 115 has search_for_mite_dir =>
47 is => rw,
48 isa => Bool,
49 default => true;
50  
51 13 ▶sub make_mite_dir {
Subroutine make_mite_dir: called CC=2 SCAR=7.0
Pod undocumented
52 13 my ( $self, $dir ) = ( shift, @_ );
53 13 ▶ $dir //= Path::Tiny->cwd;
Condition66%2/3
$dir //= "Path::Tiny"->cwd
l!l&&r!l&&!r
3100
MC/DC0%0/2
$dir //= "Path::Tiny"->cwd
$dir "Path::Tiny"->cwd
Truth table66%2/3
A //= B
A= $dirB= "Path::Tiny"->cwd
ABresult
1X1
011
000
54  
55 13 return Path::Tiny::path($dir)->child($self->mite_dir_name)->mkpath;
56 }
57  
58 10 ▶sub write_config {
Subroutine write_config: called CC=2 SCAR=7.0
Pod undocumented
59 10 my ( $self, $data ) = ( shift, @_ );
60 10 ▶ $data //= $self->data;
Condition66%2/3
$data //= $self->data
l!l&&r!l&&!r
910
MC/DC0%0/2
$data //= $self->data
$data $self->data
Truth table66%2/3
A //= B
A= $dataB= $self->data
ABresult
1X1
011
000
61  
62 10 $self->config_file->spew_utf8( $self->yaml_dump( $data ) );
63 10 return;
64 }
65  
66 4166 ▶sub dir_has_mite {
Subroutine dir_has_mite: called CC=2 SCAR=6.9
Pod undocumented
67 4166 my ( $self, $dir ) = ( shift, @_ );
68  
69 4166 my $maybe_mite = Path::Tiny::path($dir)->child($self->mite_dir_name);
70 4166 ▶ return $maybe_mite if -d $maybe_mite;
Branch: 1 branch
BranchTrueFalseTotal
if -d $maybe_mite 33 4133 4166
71 4133 return;
72 }
73  
74 858 ▶sub find_mite_dir {
Subroutine find_mite_dir: called CC=5 SCAR=16.1
Pod undocumented
75 858 my ( $self, $current ) = ( shift, @_ );
76 858 ▶ $current //= Path::Tiny->cwd;
Condition66%2/3
$current //= "Path::Tiny"->cwd
l!l&&r!l&&!r
58530
MC/DC0%0/2
$current //= "Path::Tiny"->cwd
$current "Path::Tiny"->cwd
Truth table66%2/3
A //= B
A= $currentB= "Path::Tiny"->cwd
ABresult
1X1
011
000
77  
78 858 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->search_for_mite_dir and not $current->is_rootdir and do { do { my $maybe_mite = $self->dir_has_mite($current); return $maybe_mite if $maybe_mite; $current = $current->parent } } 3299 829 4128
Condition100%3/3
$self->search_for_mite_dir and not $current->is_rootdir
!ll&&!rl&&r
38263299
MC/DC100%2/2
$self->search_for_mite_dir and not $current->is_rootdir
$self->search_for_mite_dir not $current->is_rootdir
Truth table100%3/3
A and not(B)
A= $self->search_for_mite_dirB= not $current->is_rootdir
ABresult
0X0
100
111
79 4157 my $maybe_mite = $self->dir_has_mite($current);
80 4157 ▶ return $maybe_mite if $maybe_mite;
Branch: 1 branch
BranchTrueFalseTotal
if $maybe_mite 29 4128 4157
81  
82 4128 $current = $current->parent;
83 } while $self->search_for_mite_dir && !$current->is_rootdir;
84  
85 829 return;
86 }
87  
88 93 ▶sub should_tidy {
Subroutine should_tidy: called CC=2 SCAR=9.2
Pod undocumented
89 93 my $self = shift;
90 0 ▶ $self->data->{perltidy} && eval { require Perl::Tidy; 1 };
Branch: 1 branch
BranchTrueFalseTotal
$self->data->{"perltidy"} and eval { do { require Perl::Tidy; 1 } } 0 8 8
91 }
92  
93 13 ▶sub yaml_load {
Subroutine yaml_load: called CC=1 SCAR=0.0
Pod undocumented
94 13 my ( $class, $yaml ) = ( shift, @_ );
95  
96 13 require YAML::XS;
97 13 return YAML::XS::Load($yaml);
98 }
99  
100 10 ▶sub yaml_dump {
Subroutine yaml_dump: called CC=1 SCAR=0.0
Pod undocumented
101 10 my ( $class, $data ) = ( shift, @_ );
102  
103 10 require YAML::XS;
104 10 return YAML::XS::Dump($data);
105 }
106  
107 115 1;
« lib/Mite/App.pm ↑ Summary lib/Mite/MakeMaker.pm »