line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
107
|
|
|
107
|
|
5112663
|
use 5.010001; |
|
107
|
|
|
|
|
477
|
|
2
|
107
|
|
|
107
|
|
739
|
use strict; |
|
107
|
|
|
|
|
281
|
|
|
107
|
|
|
|
|
2859
|
|
3
|
107
|
|
|
107
|
|
780
|
use warnings; |
|
107
|
|
|
|
|
340
|
|
|
107
|
|
|
|
|
6042
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Mite::Config; |
6
|
107
|
|
|
107
|
|
2193
|
use Mite::Miteception -all; |
|
107
|
|
|
|
|
289
|
|
|
107
|
|
|
|
|
1160
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
9
|
|
|
|
|
|
|
our $VERSION = '0.012000'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
return $self->find_mite_dir || |
24
|
|
|
|
|
|
|
croak "No @{[$self->mite_dir_name]} directory found.\n"; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has config_file => |
28
|
|
|
|
|
|
|
is => ro, |
29
|
|
|
|
|
|
|
isa => Path, |
30
|
|
|
|
|
|
|
coerce => true, |
31
|
|
|
|
|
|
|
lazy => true, |
32
|
|
|
|
|
|
|
default => sub { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
return $self->mite_dir->child("config"); |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has data => |
38
|
|
|
|
|
|
|
is => rw, |
39
|
|
|
|
|
|
|
isa => HashRef, |
40
|
|
|
|
|
|
|
lazy => true, |
41
|
|
|
|
|
|
|
default => sub { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
return $self->yaml_load( $self->config_file->slurp_utf8 ); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has search_for_mite_dir => |
47
|
|
|
|
|
|
|
is => rw, |
48
|
|
|
|
|
|
|
isa => Bool, |
49
|
|
|
|
|
|
|
default => true; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub make_mite_dir { |
52
|
13
|
|
|
13
|
0
|
5413
|
my ( $self, $dir ) = ( shift, @_ ); |
53
|
13
|
|
66
|
|
|
345
|
$dir //= Path::Tiny->cwd; |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
1225
|
return Path::Tiny::path($dir)->child($self->mite_dir_name)->mkpath; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub write_config { |
59
|
10
|
|
|
10
|
0
|
517
|
my ( $self, $data ) = ( shift, @_ ); |
60
|
10
|
|
66
|
|
|
53
|
$data //= $self->data; |
61
|
|
|
|
|
|
|
|
62
|
10
|
|
|
|
|
47
|
$self->config_file->spew_utf8( $self->yaml_dump( $data ) ); |
63
|
10
|
|
|
|
|
37783
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub dir_has_mite { |
67
|
3282
|
|
|
3282
|
0
|
6516
|
my ( $self, $dir ) = ( shift, @_ ); |
68
|
|
|
|
|
|
|
|
69
|
3282
|
|
|
|
|
8461
|
my $maybe_mite = Path::Tiny::path($dir)->child($self->mite_dir_name); |
70
|
3282
|
100
|
|
|
|
180792
|
return $maybe_mite if -d $maybe_mite; |
71
|
3261
|
|
|
|
|
56424
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub find_mite_dir { |
75
|
839
|
|
|
839
|
0
|
5717
|
my ( $self, $current ) = ( shift, @_ ); |
76
|
839
|
|
66
|
|
|
7688
|
$current //= Path::Tiny->cwd; |
77
|
|
|
|
|
|
|
|
78
|
839
|
|
100
|
|
|
55264
|
do { |
79
|
3281
|
|
|
|
|
59369
|
my $maybe_mite = $self->dir_has_mite($current); |
80
|
3281
|
100
|
|
|
|
8169
|
return $maybe_mite if $maybe_mite; |
81
|
|
|
|
|
|
|
|
82
|
3260
|
|
|
|
|
12150
|
$current = $current->parent; |
83
|
|
|
|
|
|
|
} while $self->search_for_mite_dir && !$current->is_rootdir; |
84
|
|
|
|
|
|
|
|
85
|
818
|
|
|
|
|
21195
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub should_tidy { |
89
|
88
|
|
|
88
|
0
|
255
|
my $self = shift; |
90
|
88
|
50
|
|
|
|
362
|
$self->data->{perltidy} && eval { require Perl::Tidy; 1 }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub yaml_load { |
94
|
9
|
|
|
9
|
0
|
11592
|
my ( $class, $yaml ) = ( shift, @_ ); |
95
|
|
|
|
|
|
|
|
96
|
9
|
|
|
|
|
3022
|
require YAML::XS; |
97
|
9
|
|
|
|
|
23516
|
return YAML::XS::Load($yaml); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub yaml_dump { |
101
|
10
|
|
|
10
|
0
|
27
|
my ( $class, $data ) = ( shift, @_ ); |
102
|
|
|
|
|
|
|
|
103
|
10
|
|
|
|
|
4927
|
require YAML::XS; |
104
|
10
|
|
|
|
|
33996
|
return YAML::XS::Dump($data); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |