Add coercions to path attributes to coerce a string to a Path::Tiny object
This fixes GitHub #66.
Dave Rolsky
7 years ago
5 | 5 | use Code::TidyAll::Cache; |
6 | 6 | use Code::TidyAll::CacheModel; |
7 | 7 | use Code::TidyAll::Config::INI::Reader; |
8 | use Code::TidyAll::Plugin; | |
8 | 9 | use Code::TidyAll::Result; |
9 | 10 | use Code::TidyAll::Util qw(can_load); |
10 | 11 | use Data::Dumper; |
15 | 16 | use List::SomeUtils qw(uniq); |
16 | 17 | use Path::Tiny qw(path); |
17 | 18 | use Scalar::Util qw(blessed); |
19 | use Specio 0.30; | |
20 | use Specio::Declare; | |
21 | use Specio::Library::Builtins; | |
22 | use Specio::Library::Numeric; | |
23 | use Specio::Library::Path::Tiny; | |
24 | use Specio::Library::String; | |
18 | 25 | use Time::Duration::Parse qw(parse_duration); |
19 | 26 | use Try::Tiny; |
20 | 27 | |
25 | 32 | sub default_conf_names { ( 'tidyall.ini', '.tidyallrc' ) } |
26 | 33 | |
27 | 34 | # External |
28 | has 'backup_ttl' => ( is => 'ro', default => '1 hour' ); | |
29 | has 'cache' => ( is => 'lazy' ); | |
30 | has 'cache_model_class' => ( is => 'ro', default => 'Code::TidyAll::CacheModel' ); | |
31 | has 'check_only' => ( is => 'ro' ); | |
32 | has 'data_dir' => ( is => 'lazy' ); | |
33 | has 'iterations' => ( is => 'ro', default => 1 ); | |
34 | has 'jobs' => ( is => 'ro', default => 1 ); | |
35 | has 'list_only' => ( is => 'ro' ); | |
36 | has 'mode' => ( is => 'ro', default => 'cli' ); | |
37 | has 'msg_outputter' => ( is => 'ro', builder => '_build_msg_outputter' ); | |
38 | has 'no_backups' => ( is => 'ro' ); | |
39 | has 'no_cache' => ( is => 'ro' ); | |
40 | has 'output_suffix' => ( is => 'ro', default => q{} ); | |
41 | has 'plugins' => ( is => 'ro', required => 1 ); | |
42 | has 'quiet' => ( is => 'ro' ); | |
43 | has 'recursive' => ( is => 'ro' ); | |
44 | has 'refresh_cache' => ( is => 'ro' ); | |
45 | has 'root_dir' => ( is => 'ro', required => 1 ); | |
46 | has 'verbose' => ( is => 'ro' ); | |
35 | has 'backup_ttl' => ( | |
36 | is => 'ro', | |
37 | isa => t('NonEmptyStr'), | |
38 | default => '1 hour', | |
39 | ); | |
40 | ||
41 | has 'cache' => ( | |
42 | is => 'lazy', | |
43 | isa => object_can_type( methods => [qw( get set )] ), | |
44 | ); | |
45 | ||
46 | has 'cache_model_class' => ( | |
47 | is => 'ro', | |
48 | isa => t('ClassName'), | |
49 | default => 'Code::TidyAll::CacheModel', | |
50 | ); | |
51 | ||
52 | has 'check_only' => ( | |
53 | is => 'ro', | |
54 | isa => t('Bool'), | |
55 | ); | |
56 | ||
57 | has 'data_dir' => ( | |
58 | is => 'lazy', | |
59 | isa => t('Path'), | |
60 | coerce => t('Path')->coercion_sub, | |
61 | ); | |
62 | ||
63 | has 'iterations' => ( | |
64 | is => 'ro', | |
65 | isa => t('PositiveInt'), | |
66 | default => 1, | |
67 | ); | |
68 | ||
69 | has 'jobs' => ( | |
70 | is => 'ro', | |
71 | isa => t('Int'), | |
72 | default => 1, | |
73 | ); | |
74 | ||
75 | has 'list_only' => ( | |
76 | is => 'ro', | |
77 | isa => t('Bool'), | |
78 | ); | |
79 | ||
80 | has 'mode' => ( | |
81 | is => 'ro', | |
82 | isa => t('NonEmptyStr'), | |
83 | default => 'cli', | |
84 | ); | |
85 | ||
86 | has 'msg_outputter' => ( | |
87 | is => 'ro', | |
88 | isa => t('CodeRef'), | |
89 | builder => '_build_msg_outputter', | |
90 | ); | |
91 | ||
92 | has 'no_backups' => ( | |
93 | is => 'ro', | |
94 | isa => t('Bool'), | |
95 | ); | |
96 | ||
97 | has 'no_cache' => ( | |
98 | is => 'ro', | |
99 | isa => t('Bool'), | |
100 | ); | |
101 | ||
102 | has 'output_suffix' => ( | |
103 | is => 'ro', | |
104 | isa => t('Str'), | |
105 | default => q{}, | |
106 | ); | |
107 | ||
108 | has 'plugins' => ( | |
109 | is => 'ro', | |
110 | ias => t('HashRef'), | |
111 | required => 1, | |
112 | ); | |
113 | ||
114 | has 'quiet' => ( | |
115 | is => 'ro', | |
116 | isa => t('Bool'), | |
117 | ); | |
118 | has 'recursive' => ( | |
119 | is => 'ro', | |
120 | isa => t('Bool'), | |
121 | ); | |
122 | ||
123 | has 'refresh_cache' => ( | |
124 | is => 'ro', | |
125 | isa => t('Bool'), | |
126 | ); | |
127 | ||
128 | has 'root_dir' => ( | |
129 | is => 'ro', | |
130 | isa => t('RealDir')->_subify, | |
131 | coerce => t('RealDir')->coercion_sub, | |
132 | required => 1 | |
133 | ); | |
134 | ||
135 | has 'verbose' => ( | |
136 | is => 'ro', | |
137 | isa => t('Bool'), | |
138 | default => 0, | |
139 | ); | |
47 | 140 | |
48 | 141 | # Internal |
49 | has 'backup_dir' => ( is => 'lazy', init_arg => undef ); | |
50 | has 'backup_ttl_secs' => ( is => 'lazy', init_arg => undef ); | |
51 | has 'base_sig' => ( is => 'lazy', init_arg => undef ); | |
52 | has 'plugin_objects' => ( is => 'lazy', init_arg => undef ); | |
53 | has 'plugins_for_mode' => ( is => 'lazy', init_arg => undef ); | |
142 | has 'backup_dir' => ( | |
143 | is => 'lazy', | |
144 | isa => t('Path'), | |
145 | init_arg => undef, | |
146 | ); | |
147 | ||
148 | has 'backup_ttl_secs' => ( | |
149 | is => 'lazy', | |
150 | isa => t('Int'), | |
151 | init_arg => undef, | |
152 | ); | |
153 | ||
154 | has 'base_sig' => ( | |
155 | is => 'lazy', | |
156 | isa => t('NonEmptyStr'), | |
157 | init_arg => undef, | |
158 | ); | |
159 | ||
160 | has 'plugin_objects' => ( | |
161 | is => 'lazy', | |
162 | isa => t( 'ArrayRef', of => object_isa_type('Code::TidyAll::Plugin') ), | |
163 | init_arg => undef, | |
164 | ); | |
165 | ||
166 | has 'plugins_for_mode' => ( | |
167 | is => 'lazy', | |
168 | isa => t( 'HashRef', of => t('HashRef') ), | |
169 | init_arg => undef, | |
170 | ); | |
54 | 171 | |
55 | 172 | with 'Code::TidyAll::Role::Tempdir'; |
56 | 173 | |
118 | 235 | ); |
119 | 236 | } |
120 | 237 | |
121 | $self->{root_dir} = path( $self->{root_dir} )->realpath; | |
122 | 238 | $self->{plugins_for_path} = {}; |
123 | 239 | |
124 | 240 | unless ( $self->no_backups ) { |