| 1 | package Code::TidyAll; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 58 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 58 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 58 | ▶ | use Code::TidyAll::Cache; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 58 | ▶ | use Code::TidyAll::CacheModel; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 58 | ▶ | use Code::TidyAll::Config::INI::Reader; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 58 | ▶ | use Code::TidyAll::Plugin; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 58 | ▶ | use Code::TidyAll::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 58 | ▶ | use Code::TidyAll::Zglob qw(zglob); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 58 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 58 | ▶ | use Date::Format; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 58 | ▶ | use Digest::SHA qw(sha1_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 58 | ▶ | use File::Find qw(find); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 58 | ▶ | use File::pushd qw( pushd ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 58 | ▶ | use List::SomeUtils qw(uniq); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 58 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 58 | ▶ | use Path::Tiny qw(path); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 58 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 58 | ▶ | use Specio 0.40; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 58 | ▶ | use Specio::Declare; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 58 | ▶ | use Specio::Library::Builtins; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 58 | ▶ | use Specio::Library::Numeric; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 58 | ▶ | use Specio::Library::Path::Tiny 0.04; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 58 | ▶ | use Specio::Library::String; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 58 | ▶ | use Time::Duration::Parse qw(parse_duration); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 58 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 58 | ▶ | use Moo 2.000000; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 58 | our $VERSION = '0.85'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 31 | ▶ | sub default_conf_names { ( 'tidyall.ini', '.tidyallrc' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_conf_names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # External | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 58 | has backup_ttl => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => t('NonEmptyStr'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | default => '1 hour', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 58 | has cache => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | isa => object_can_type( methods => [qw( get set )] ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 58 | has cache_model_class => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | isa => t('ClassName'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | default => 'Code::TidyAll::CacheModel', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 58 | has check_only => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 58 | has data_dir => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | isa => t('Path'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | coerce => t('Path')->coercion_sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 58 | has iterations => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | isa => t('PositiveInt'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 58 | has jobs => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | isa => t('Int'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 58 | has list_only => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 58 | has mode => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | isa => t('NonEmptyStr'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | default => 'cli', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 58 | has msg_outputter => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | isa => t('CodeRef'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | builder => '_build_msg_outputter', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 58 | has no_backups => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 58 | has no_cache => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 58 | has output_suffix => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | isa => t('Str'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | default => q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 58 | has plugins => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | isa => t('HashRef'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | has selected_plugins => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | isa => t( 'ArrayRef', of => t('NonEmptyStr') ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 96 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 58 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 58 | has quiet => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 58 | has recursive => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 58 | has refresh_cache => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 58 | has root_dir => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | isa => t('RealDir'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | coerce => t('RealDir')->coercion_sub, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | required => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 58 | has verbose => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | isa => t('Bool'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | has inc => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | isa => t( 'ArrayRef', of => t('NonEmptyStr') ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 102 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 58 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 58 | has _backup_dir => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | isa => t('Path'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | builder => '_build_backup_dir', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 58 | has _backup_ttl_secs => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | isa => t('Int'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | builder => '_build_backup_ttl_secs', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 58 | has _base_sig => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | isa => t('NonEmptyStr'), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | builder => '_build_base_sig', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 58 | has _plugin_objects => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | isa => t( 'ArrayRef', of => object_isa_type('Code::TidyAll::Plugin') ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | builder => '_build_plugin_objects', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 58 | has _plugins_to_run => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | isa => t( 'HashRef', of => t('HashRef') ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | builder => '_build_plugins_to_run', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | has _plugins_for_path => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | isa => t( 'HashRef', of => t('HashRef') ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 93 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 58 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 58 | with qw( Code::TidyAll::Role::HasIgnore Code::TidyAll::Role::Tempdir ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 88 | ▶ | sub _build_backup_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_backup_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 88 | return $self->data_dir->child('backups'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 88 | ▶ | sub _build_backup_ttl_secs { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_backup_ttl_secs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 88 | return parse_duration( $self->backup_ttl ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 59 | ▶ | sub _build_base_sig { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_base_sig: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 59 | my $active_plugins = join( q{|}, map { $_->name } @{ $self->_plugin_objects } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 59 | ▶ | return $self->_sig( [ $Code::TidyAll::VERSION || 0, $active_plugins ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Code::TidyAll::VERSION || 0
MC/DC0%0/1
$Code::TidyAll::VERSION || 0
$Code::TidyAll::VERSION
Truth table50%1/2
A
A= $Code::TidyAll::VERSION
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 59 | ▶ | sub _sig { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 59 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 59 | return sha1_hex( join( ',', @$data ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 86 | ▶ | sub _build_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cache: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 86 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 86 | return Code::TidyAll::Cache->new( cache_dir => $self->data_dir->child('cache') ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 96 | ▶ | sub _build_data_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_data_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 96 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 96 | return $self->root_dir->child('/.tidyall.d'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 98 | ▶ | sub _build_plugins_to_run { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_plugins_to_run: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 98 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 98 | my $all_plugins = $self->plugins; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 98 | my %selected = map { $_ => 1 } @{ $self->selected_plugins }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 98 | my %plugins; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 98 | ▶ | if (%selected) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my @unknown = sort grep { !$all_plugins->{$_} } keys %selected; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | ▶ | die "Asked for unknown plugins: [@unknown]" if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | %plugins = map { $_ => $all_plugins->{$_} } keys %selected; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | elsif ( my $mode = $self->mode ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 119 | %plugins = map { $_ => $all_plugins->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 120 | grep { $self->_plugin_conf_matches_mode( $all_plugins->{$_}, $mode ) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 96 | keys %{$all_plugins}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 97 | return \%plugins; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 120 | ▶ | sub _plugin_conf_matches_mode { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plugin_conf_matches_mode: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 120 | my ( $self, $conf, $mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 120 | ▶ | if ( my $only_modes = $conf->{only_modes} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | ▶ | return 0 if ( q{ } . $only_modes . q{ } ) !~ / $mode /; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 119 | ▶ | if ( my $except_modes = $conf->{except_modes} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return 0 if ( q{ } . $except_modes . q{ } ) =~ / $mode /; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 119 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 98 | ▶ | sub _build_plugin_objects { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_plugin_objects: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 98 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # Sort tidiers by weight (by default validators have a weight of 60 and non- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # validators a weight of 50 meaning non-validators normally go first), then | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # alphabetical | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # TODO: These should probably sort in a consistent way independent of locale | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 37 | ▶ | sort { ( $a->weight <=> $b->weight ) || ( $a->name cmp $b->name ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$a->weight <=> $b->weight || $a->name cmp $b->name
MC/DC0%0/2
$a->weight <=> $b->weight || $a->name cmp $b->name
$a->weight <=> $b->weight
$a->name cmp $b->name
Truth table66%2/3
A || B
A= $a->weight <=> $b->weightB= $a->name cmp $b->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 121 | map { $self->_load_plugin( $_, $self->_plugins_to_run->{$_} ) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 98 | keys %{ $self->_plugins_to_run } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 121 | ▶ | sub _load_plugin { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_plugin: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 121 | my ( $self, $plugin_name, $plugin_conf ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # Extract first name in case there is a description | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 121 | my ($plugin_fname) = ( $plugin_name =~ /^(\S+)/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 121 | ▶ | my $plugin_class = ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | $plugin_fname =~ /^\+/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ? substr( $plugin_fname, 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | : "Code::TidyAll::Plugin::$plugin_fname" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 121 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 121 | ▶ | use_module($plugin_class) || die 'not found'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | die qq{could not load plugin class '$plugin_class': $_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 121 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 120 | return $plugin_class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | name => $plugin_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | tidyall => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | %$plugin_conf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 105 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 105 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # Strict constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 105 | ▶ | if ( my @bad_params = grep { !$self->can($_) } keys(%$params) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | die sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 'unknown constructor param%s %s for %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | @bad_params > 1 ? 's' : q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | join( ', ', sort map {qq['$_']} @bad_params ), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ref($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 104 | ▶ | unless ( $self->no_backups ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 88 | $self->_backup_dir->mkpath( { mode => 0775 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 88 | $self->_purge_backups_periodically(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 104 | @INC = ( @{ $self->inc }, @INC ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 88 | ▶ | sub _purge_backups_periodically { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_purge_backups_periodically: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 88 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 88 | my $cache = $self->cache; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 88 | ▶ | my $last_purge_backups = $cache->get('last_purge_backups') || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$cache->get('last_purge_backups') || 0
MC/DC100%1/1
$cache->get('last_purge_backups') || 0
$cache->get('last_purge_backups')
Truth table100%2/2
A
A= $cache->get('last_purge_backups')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 88 | ▶ | if ( time > $last_purge_backups + $self->_backup_ttl_secs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 53 | $self->_purge_backups(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 53 | $cache->set( 'last_purge_backups', time() ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 53 | ▶ | sub _purge_backups { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_purge_backups: called CC=2 SCAR=7.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 53 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 53 | ▶ | $self->msg('purging old backups') if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | find( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | follow => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 53 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 53 | ▶ | unlink $_ if -f && /\.bak$/ && time > ( stat($_) )[9] + $self->_backup_ttl_secs; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-f $_ and /\.bak$/ and time > (stat $_)[9] + $self->_backup_ttl_secs
-f $_ and /\.bak$/
MC/DC0%0/3
-f $_ and /\.bak$/ and time > (stat $_)[9] + $self->_backup_ttl_secs
-f $_
/\.bak$/
time > (stat $_)[9] + $self->_backup_ttl_secs
Truth table25%1/4
A and B and C
A= -f $_B= /\.bak$/C= time > (stat $_)[9] + $self->_backup_ttl_secs
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 53 | no_chdir => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $self->_backup_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 30 | ▶ | sub new_from_conf_file { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_conf_file: called CC=8 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 30 | my ( $class, $conf_file, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 30 | $conf_file = path($conf_file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 30 | ▶ | die qq{no such file '$conf_file'} unless $conf_file->is_file; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 30 | my $conf_params = $class->_read_conf_file($conf_file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 30 | ▶ | my $main_params = delete( $conf_params->{'_'} ) || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $conf_params->{'_'} || {}
MC/DC100%1/1
delete $conf_params->{'_'} || {}
delete $conf_params->{'_'}
Truth table100%2/2
A
A= delete $conf_params->{'_'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | %params = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | plugins => $conf_params, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | root_dir => path($conf_file)->realpath->parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 30 | %{$main_params}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | %params | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Initialize with alternate class if given | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 30 | ▶ | if ( my $tidyall_class = delete( $params{tidyall_class} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | local @INC = ( @{ $conf_params->{inc} }, @INC ) if $conf_params->{inc}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | use_module($tidyall_class) or die qq{cannot load '$tidyall_class'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $class = $tidyall_class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 30 | ▶ | if ( $params{verbose} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 19 | ▶ | my $msg_outputter = $params{msg_outputter} || $class->_build_msg_outputter(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{'msg_outputter'} || $class->_build_msg_outputter
MC/DC0%0/2
$params{'msg_outputter'} || $class->_build_msg_outputter
$params{'msg_outputter'}
$class->_build_msg_outputter
Truth table33%1/3
A || B
A= $params{'msg_outputter'}B= $class->_build_msg_outputter
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 19 | $msg_outputter->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 'constructing %s with these params: %s', $class, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | _dump_params( \%params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 30 | return $class->new(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 30 | ▶ | sub _read_conf_file { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_conf_file: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 30 | my ( $class, $conf_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 30 | my $conf_string = $conf_file->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 30 | my $root_dir = $conf_file->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 30 | $conf_string =~ s/\$ROOT/$root_dir/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 30 | my $conf_hash = Code::TidyAll::Config::INI::Reader->read_string($conf_string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 30 | ▶ | die qq{'$conf_file' did not evaluate to a hash} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | unless ( ref($conf_hash) eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 30 | return $conf_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 19 | ▶ | sub _dump_params { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 19 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 19 | return Data::Dumper->new( [ _recurse_dump($p) ] ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | ->Indent(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ->Sortkeys(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | ->Quotekeys(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | ->Terse(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | ->Dump; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # This is all a ridiculous workaround around the fact that there is no good | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # way to tell Data::Dumper how to serialize a Path::Tiny object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 19 | ▶ | sub _recurse_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_recurse_dump: called CC=12 SCAR=37.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 19 | my ($p) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 19 | ▶ | return $p unless ref $p; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 19 | ▶ | if ( ref $p eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 19 | my %dump; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 19 | for my $k ( keys %{$p} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 110 | my $v = $p->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 110 | ▶ | if ( blessed $v ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 19 | ▶ | if ( $v->isa('Path::Tiny') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 19 | $dump{$k} = $v . q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | die 'Cannot dump ' . ref($v) . ' object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | elsif ( ref $v =~ /^(?:HASH|ARRAY)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $dump{$k} = _recurse_dump($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 91 | $dump{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 19 | return \%dump; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | elsif ( ref $p eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my @dump; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | for my $v ( @{$p} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ( blessed $v ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( $v->isa('Path::Tiny') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | push @dump, $v . q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | die 'Cannot dump ' . ref($v) . ' object'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | elsif ( ref $v =~ /^(?:HASH|ARRAY)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | push @dump, _recurse_dump($v); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | push @dump, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return \@dump; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | die "_recurse_dump was called with a value that was not a scalar, hashref, or an arrayref: $p"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 17 | ▶ | sub process_all { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 17 | return $self->process_paths( $self->find_matched_files ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 115 | ▶ | sub process_paths { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_paths: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 115 | my ( $self, @paths ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | @paths = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 139 | ▶ | try { $_->realpath } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 139 | ▶ | || $_->absolute | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
&try(sub {
$_->realpath;
}
) || $_->absolute
MC/DC0%0/2
&try(sub {
$_->realpath;
}
) || $_->absolute
&try(sub {
$_->realpath;
}
)
$_->absolute
Truth table66%2/3
A || B
A= &try(sub {
$_->realpath;
}
)B= $_->absolute
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 115 | } map { path($_) } @paths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 115 | my $dir = pushd( $self->root_dir ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 115 | ▶ | if ( $self->jobs > 1 && @paths > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->jobs > 1 and @paths > 1
MC/DC50%1/2
$self->jobs > 1 and @paths > 1
$self->jobs > 1
@paths > 1
Truth table66%2/3
A and B
A= $self->jobs > 1B= @paths > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 5 | return $self->_process_parallel(@paths); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 110 | return map { $self->process_path($_) } @paths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | ▶ | sub _process_parallel { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_parallel: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | my ( $self, @paths ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 5 | ▶ | unless ( eval { require Parallel::ForkManager; 1; } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | die 'Running Code::TidyAll with multiple jobs requires Parallel::ForkManager'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 5 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | my %path_to_pid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 5 | my $pm = Parallel::ForkManager->new( $self->jobs ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 5 | $pm->set_waitpid_blocking_sleep(0.01); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | $pm->run_on_finish( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 5 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 5 | my ( $pid, $code, $result ) = @_[ 0, 1, 5 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 5 | ▶ | if ($code) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | warn "Error running tidyall on $path_to_pid{$pid}. Got exit status of $code."; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 5 | push @results, $result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 5 | for my $path (@paths) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 14 | ▶ | if ( my $pid = $pm->start ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 10 | $path_to_pid{$path} = $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | $pm->finish( 0, $self->process_path($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | $pm->wait_all_children; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 123 | ▶ | sub process_path { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_path: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 123 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 123 | ▶ | if ( $path->is_dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | ▶ | if ( $self->recursive ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | return $self->process_paths( $path->children ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | return ( $self->_error_result( "$path: is a directory (try -r/--recursive)", $path ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | elsif ( $path->is_file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 120 | return ( $self->process_file($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | return ( $self->_error_result( "$path: not a file or directory", $path ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 122 | ▶ | sub process_file { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_file: called CC=11 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 122 | my ( $self, $full_path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 122 | $full_path = path($full_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 122 | ▶ | die "$full_path is not a file" unless $full_path->is_file; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 122 | my $path = $self->_small_path($full_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 121 | ▶ | if ( $self->list_only ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | if ( my @plugins = $self->plugins_for_path($path) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $self->msg( '%s (%s)', $path, join( ', ', map { $_->name } @plugins ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | return Code::TidyAll::Result->new( path => $path, state => 'checked' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 121 | my $cache_model = $self->_cache_model_for( $path, $full_path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 121 | ▶ | if ( $self->refresh_cache ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | $cache_model->remove; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | elsif ( $cache_model->is_cached ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 8 | ▶ | $self->msg( '[cached] %s', $path ) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 8 | return Code::TidyAll::Result->new( path => $path, state => 'cached' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 113 | ▶ | my $contents = $cache_model->file_contents || $full_path->slurp_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$cache_model->file_contents || $full_path->slurp_raw
MC/DC50%1/2
$cache_model->file_contents || $full_path->slurp_raw
$cache_model->file_contents
$full_path->slurp_raw
Truth table66%2/3
A || B
A= $cache_model->file_contentsB= $full_path->slurp_raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 113 | my $result = $self->process_source( $contents, $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 113 | ▶ | if ( $result->state eq 'tidied' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # backup original contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 60 | $self->_backup_file( $path, $contents ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # write new contents out to disk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 60 | $contents = $result->new_contents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # We don't use ->spew because that creates a new file and renames it, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # losing the existing mode setting in the process. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 60 | path( $full_path . $self->output_suffix )->append_raw( { truncate => 1 }, $contents ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # change the in memory contents of the cache (but don't update yet) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 60 | ▶ | $cache_model->file_contents($contents) unless $self->output_suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 113 | ▶ | $cache_model->update if $result->ok; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 113 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 126 | ▶ | sub _small_path { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_small_path: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 126 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 126 | ▶ | die sprintf( q{'%s' is not underneath root dir '%s'!}, $path, $self->root_dir ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | unless index( $path, $self->root_dir ) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 125 | return path( substr( $path . q{}, length( $self->root_dir ) + 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 143 | ▶ | sub plugins_for_path { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plugins_for_path: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 143 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | $self->_plugins_for_path->{$path} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 143 | ▶ | ||= [ grep { $_->matches_path($path) } @{ $self->_plugin_objects } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_plugins_for_path->{$path} ||= [grep({$_->matches_path($path);} @{$self->_plugin_objects;})]
MC/DC100%1/1
$self->_plugins_for_path->{$path} ||= [grep({$_->matches_path($path);} @{$self->_plugin_objects;})]
$self->_plugins_for_path->{$path}
Truth table100%2/2
A
A= $self->_plugins_for_path->{$path}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 143 | return @{ $self->_plugins_for_path->{$path} }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 121 | ▶ | sub _cache_model_for { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cache_model_for: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 121 | my ( $self, $path, $full_path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 121 | ▶ | return $self->cache_model_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | full_path => $full_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | ( $self->no_cache ? () : ( cache_engine => $self->cache ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | base_sig => $self->_base_sig, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 60 | ▶ | sub _backup_file { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_backup_file: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 60 | my ( $self, $path, $contents ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 60 | ▶ | unless ( $self->no_backups ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 44 | my $backup_file = $self->_backup_dir->child( $self->_backup_filename($path) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 44 | $backup_file->parent->mkpath( { mode => 0775 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 44 | $backup_file->spew_raw($contents); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 44 | ▶ | sub _backup_filename { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_backup_filename: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 44 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 44 | return join( q{}, $path, '-', time2str( '%Y%m%d-%H%M%S', time ), '.bak' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 142 | ▶ | sub process_source { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_source: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 142 | my ( $self, $contents, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 142 | $path = path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 142 | ▶ | die 'contents and path required' unless defined($contents) && defined($path); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $contents and defined $path
MC/DC0%0/2
defined $contents and defined $path
defined $contents
defined $path
Truth table33%1/3
A and B
A= defined $contentsB= defined $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 142 | my @plugins = $self->plugins_for_path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 142 | ▶ | if ( !@plugins ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | $self->msg( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | '[no plugins apply%s] %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | $self->mode ? q{ for mode '} . $self->mode . q{'} : q{}, $path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | ) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | return Code::TidyAll::Result->new( path => $path, state => 'no_match' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 141 | ▶ | if ( $self->verbose ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 26 | my @names = join ', ', map { $_->name } @plugins; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 26 | $self->msg("[applying the following plugins: @names]"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 141 | my $new_contents = my $orig_contents = $contents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 141 | my $plugin; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | my $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 141 | my @diffs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 141 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 141 | foreach my $method (qw(preprocess_source process_source_or_file postprocess_source)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 408 | foreach $plugin (@plugins) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 476 | my $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 476 | ( $new_contents, $diff ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | = $plugin->$method( $new_contents, $path, $self->check_only ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 461 | ▶ | if ($diff) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 2 | push @diffs, [ $plugin->name, $diff ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 15 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 15 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 15 | $error = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 15 | ▶ | $error = sprintf( q{*** '%s': %s}, $plugin->name, $_ ) if $plugin; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 141 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 141 | ▶ | my $was_tidied = !$error && ( $new_contents ne $orig_contents ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!$error && $new_contents ne $orig_contents
MC/DC100%2/2
!$error && $new_contents ne $orig_contents
!$error
$new_contents ne $orig_contents
Truth table100%3/3
not(A) && B
A= !$errorB= $new_contents ne $orig_contents
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 141 | ▶ | if ( $was_tidied && $self->check_only ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$was_tidied and $self->check_only
MC/DC100%2/2
$was_tidied and $self->check_only
$was_tidied
$self->check_only
Truth table100%3/3
A and B
A= $was_tidiedB= $self->check_only
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 12 | $error = '*** needs tidying'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # Github annotations parsable output to highlight code in pull requests | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 12 | ▶ | if ( $ENV{GITHUB_ACTIONS} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | $error .= "\n::error file=${path}::File ${path} needs tidying"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 12 | foreach my $diff (@diffs) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 2 | $error .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 2 | $error .= "$diff->[0] made the following change:\n$diff->[1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 12 | ▶ | $error .= "\n\n" if @diffs; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 12 | undef $was_tidied; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 141 | ▶ | if ( !$self->quiet || $error ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->quiet or $error
MC/DC100%2/2
not $self->quiet or $error
not $self->quiet
$error
Truth table100%3/3
not(A) or B
A= not $self->quietB= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 122 | ▶ | my $status = $was_tidied ? '[tidied] ' : '[checked] '; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | my $plugin_names | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 122 | ▶ | = $self->verbose ? sprintf( ' (%s)', join( ', ', map { $_->name } @plugins ) ) : q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 122 | $self->msg( '%s%s%s', $status, $path, $plugin_names ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 141 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 27 | return $self->_error_result( $error, $path, $orig_contents, $new_contents ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | elsif ($was_tidied) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 68 | return Code::TidyAll::Result->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | state => 'tidied', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | orig_contents => $orig_contents, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | new_contents => $new_contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 46 | return Code::TidyAll::Result->new( path => $path, state => 'checked' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 29 | ▶ | sub _error_result { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error_result: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 29 | my ( $self, $msg, $path, $orig_contents, $new_contents ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 29 | $self->msg( '%s', $msg ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 29 | ▶ | return Code::TidyAll::Result->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $orig_contents and length $orig_contents
defined $new_contents and length $new_contents
MC/DC50%1/2
defined $orig_contents and length $orig_contents
defined $orig_contents
length $orig_contents
MC/DC50%1/2
defined $new_contents and length $new_contents
defined $new_contents
length $new_contents
Truth table66%2/3
A and B
A= defined $orig_contentsB= length $orig_contents
Truth table66%2/3
A and B
A= defined $new_contentsB= length $new_contents
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | state => 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | error => $msg, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | ( defined $orig_contents && length $orig_contents ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | ? ( orig_contents => $orig_contents ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | ( defined $new_contents && length $new_contents ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | ? ( new_contents => $new_contents ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 10 | ▶ | sub find_conf_file { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_conf_file: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 10 | my ( $class, $conf_names, $start_dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 10 | $start_dir = path($start_dir); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 10 | my $path1 = $start_dir->absolute; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 10 | my $path2 = $start_dir->realpath; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 10 | ▶ | my $conf_file = $class->_find_conf_file_upward( $conf_names, $path1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$class->_find_conf_file_upward($conf_names, $path1) || $class->_find_conf_file_upward($conf_names, $path2)
MC/DC50%1/2
$class->_find_conf_file_upward($conf_names, $path1) || $class->_find_conf_file_upward($conf_names, $path2)
$class->_find_conf_file_upward($conf_names, $path1)
$class->_find_conf_file_upward($conf_names, $path2)
Truth table66%2/3
A || B
A= $class->_find_conf_file_upward($conf_names, $path1)B= $class->_find_conf_file_upward($conf_names, $path2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | || $class->_find_conf_file_upward( $conf_names, $path2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 10 | ▶ | unless ( defined $conf_file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 2 | ▶ | die sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 'could not find %s upwards from %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | join( ' or ', @$conf_names ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | ( $path1 eq $path2 ) ? qq{'$path1'} : qq{'$path1' or '$path2'} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 8 | return $conf_file; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 12 | ▶ | sub _find_conf_file_upward { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_conf_file_upward: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 12 | my ( $class, $conf_names, $search_dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 12 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 12 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 28 | foreach my $conf_name (@$conf_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 52 | my $try_path = $search_dir->child($conf_name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 52 | ▶ | return $try_path if $try_path->is_file; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 20 | my $parent = $search_dir->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 20 | ▶ | last if $parent eq $search_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 16 | $search_dir = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 16 | ▶ | die 'inf loop!' if ++$cnt > 100; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 19 | ▶ | sub find_matched_files { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_matched_files: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 19 | my $plugins_for_path = $self->_plugins_for_path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 19 | my $root_length = length( $self->root_dir ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 19 | my @all; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 19 | for my $plugin ( @{ $self->_plugin_objects } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 30 | my @matched = $self->_matched_by_plugin($plugin); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 30 | push @all, @matched; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # When we end up in process_source we'll need to know which plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # match a given file. This could be (re-)calculated When we call | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # ->plugins_for_path($file) there but since we already know the path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # to plugin mapping, we might as well store it here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 30 | for my $file (@matched) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 54 | my $path = substr( $file, $root_length + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 54 | ▶ | $plugins_for_path->{$path} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plugins_for_path->{$path} ||= []
MC/DC100%1/1
$plugins_for_path->{$path} ||= []
$plugins_for_path->{$path}
Truth table100%2/2
A
A= $plugins_for_path->{$path}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 54 | push @{ $plugins_for_path->{$path} }, $plugin; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 19 | return map { path($_) } uniq(@all); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 30 | ▶ | sub _matched_by_plugin { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matched_by_plugin: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 30 | my $plugin = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 7 | my %is_ignored = map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 30 | ▶ | $self->_zglob( [ @{ $self->ignores || [] }, @{ $plugin->ignores || [] } ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$self->ignores || []
$plugin->ignores || []
MC/DC0%0/1
$self->ignores || []
$self->ignores
MC/DC0%0/1
$plugin->ignores || []
$plugin->ignores
Truth table50%1/2
A
A= $self->ignores
Truth table50%1/2
A
A= $plugin->ignores
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | my @matched | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 30 | ▶ | = grep { !$is_ignored{$_} } grep { -f && -s && !-l } $self->_zglob( $plugin->selects ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
-f $_ && -s $_ && !(-l $_)
-f $_ and -s $_
MC/DC66%2/3
-f $_ && -s $_ && !(-l $_)
-f $_
-s $_
!(-l $_)
Truth table75%3/4
A and B && not(C)
A= -f $_B= -s $_C= !(-l $_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 30 | ▶ | my $shebang = $plugin->shebang | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | or return @matched; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1 | my $re = join '|', map {quotemeta} @{$shebang}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 1 | $re = qr/^#!.*\b(?:$re)\b/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | return grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 1 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 6 | ▶ | open $fh, '<', $_ or die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 6 | scalar <$fh> =~ /$re/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | } @matched; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 60 | ▶ | sub _zglob { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zglob: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 60 | my ( $self, $globs ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 60 | local $Code::TidyAll::Zglob::NOCASE = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 60 | my @files; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 60 | foreach my $glob (@$globs) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 43 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 43 | push @files, zglob( join( "/", $self->root_dir, $glob ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | die qq{error parsing '$glob': $_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 43 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 60 | return uniq(@files); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 188 | ▶ | sub msg { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
msg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 188 | my ( $self, $format, @params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 188 | $self->msg_outputter()->( $format, @params ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 124 | ▶ | sub _build_msg_outputter { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_msg_outputter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 207 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 207 | my $format = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 207 | printf "$format\n", @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 124 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 58 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | # ABSTRACT: Engine for tidyall, your all-in-one code tidier and validator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||