Code-TidyAll

 view release on metacpan or  search on metacpan

lib/Code/TidyAll.pm  view on Meta::CPAN


use Code::TidyAll::Cache;
use Code::TidyAll::CacheModel;
use Code::TidyAll::Config::INI::Reader;
use Code::TidyAll::Plugin;
use Code::TidyAll::Result;
use Code::TidyAll::Zglob qw(zglob);
use Data::Dumper;
use Date::Format;
use Digest::SHA     qw(sha1_hex);
use File::Find      qw(find);
use File::pushd     qw( pushd );
use List::SomeUtils qw(uniq);
use Module::Runtime qw( use_module );
use Path::Tiny      qw(path);
use Scalar::Util    qw(blessed);
use Specio 0.40;
use Specio::Declare;
use Specio::Library::Builtins;
use Specio::Library::Numeric;
use Specio::Library::Path::Tiny 0.04;
use Specio::Library::String;
use Time::Duration::Parse qw(parse_duration);
use Try::Tiny;

use Moo 2.000000;

our $VERSION = '0.85';

sub default_conf_names { ( 'tidyall.ini', '.tidyallrc' ) }

# External
has backup_ttl => (
    is      => 'ro',
    isa     => t('NonEmptyStr'),
    default => '1 hour',
);

has cache => (
    is  => 'lazy',
    isa => object_can_type( methods => [qw( get set )] ),
);

has cache_model_class => (
    is      => 'ro',
    isa     => t('ClassName'),
    default => 'Code::TidyAll::CacheModel',
);

has check_only => (
    is  => 'ro',
    isa => t('Bool'),
);

has data_dir => (
    is     => 'lazy',
    isa    => t('Path'),
    coerce => t('Path')->coercion_sub,
);

has iterations => (
    is      => 'ro',
    isa     => t('PositiveInt'),
    default => 1,
);

has jobs => (
    is      => 'ro',
    isa     => t('Int'),
    default => 1,
);

has list_only => (
    is  => 'ro',
    isa => t('Bool'),
);

has mode => (
    is      => 'ro',
    isa     => t('NonEmptyStr'),
    default => 'cli',
);

has msg_outputter => (
    is      => 'ro',
    isa     => t('CodeRef'),
    builder => '_build_msg_outputter',
);

has no_backups => (
    is  => 'ro',
    isa => t('Bool'),
);

has no_cache => (
    is  => 'ro',
    isa => t('Bool'),
);

has output_suffix => (
    is      => 'ro',
    isa     => t('Str'),
    default => q{},
);

has plugins => (
    is       => 'ro',
    isa      => t('HashRef'),
    required => 1,
);

has selected_plugins => (
    is      => 'ro',
    isa     => t( 'ArrayRef', of => t('NonEmptyStr') ),
    lazy    => 1,
    default => sub { [] },
);

has quiet => (
    is  => 'ro',
    isa => t('Bool'),

lib/Code/TidyAll.pm  view on Meta::CPAN


Takes a conf file path, followed optionally by a set of key/value parameters.
Reads parameters out of the conf file and combines them with the passed
parameters (the latter take precedence), and calls the regular constructor.

If the conf file or params defines I<tidyall_class>, then that class is
constructed instead of C<Code::TidyAll>.

=head3 Constructor parameters

=over 4

=item * plugins

Specify a hash of plugins, each of which is itself a hash of options. This is
equivalent to what would be parsed out of the sections in the configuration
file.

=item * selected_plugins

An arrayref of plugins to be used. This overrides the C<mode> parameter.

This is really only useful if you're getting configuration from a config file
and want to narrow the set of plugins to be run.

Note that plugins will still only run on files which match their C<select> and
C<ignore> configuration.

=item * cache_model_class

The cache model class. Defaults to C<Code::TidyAll::CacheModel>

=item * cache

The cache instance (e.g. an instance of C<Code::TidyAll::Cache> or a C<CHI>
instance.) An instance of C<Code::TidyAll::Cache> is automatically instantiated
by default.

=item * backup_ttl

=item * check_only

If this is true, then we simply check that files pass validation steps and that
tidying them does not change the file. Any changes from tidying are not
actually written back to the file.

=item * no_cleanup

A boolean indicating if we should skip cleaning temporary files or not.
Defaults to false.

=item * inc

An arrayref of directories to prepend to C<@INC>. This can be set via the
command-line as C<-I>, but you can also set it in a config file.

This affects both loading and running plugins.

=item * data_dir

=item * iterations

=item * mode

=item * no_backups

=item * no_cache

=item * output_suffix

=item * quiet

=item * root_dir

=item * ignore

=item * verbose

These options are the same as the equivalent C<tidyall> command-line options,
replacing dashes with underscore (e.g. the C<backup-ttl> option becomes
C<backup_ttl> here).

=item * msg_outputter

This is a subroutine reference that is called whenever a message needs to be
printed in some way. The sub receives a C<sprintf()> format string followed by
one or more parameters. The default sub used simply calls C<printf "$format\n",
@_> but L<Test::Code::TidyAll> overrides this to use the C<<
Test::Builder->diag >> method.

=back

=head2 $tidyall->process_paths( $path, ... )

This method iterates through a list of paths, processing all the files it
finds. It will descend into subdirectories if C<recursive> flag is true.
Returns a list of L<Code::TidyAll::Result> objects, one for each file.

=head2 $tidyall->process_file( $file )

Process the one I<file>, meaning:

=over 4

=item *

Check the cache and return immediately if file has not changed.

=item *

Apply appropriate matching plugins.

=item *

Print success or failure result to STDOUT, depending on quiet/verbose settings.

=item *

Write to the cache if caching is enabled.

=item *



( run in 0.588 second using v1.01-cache-2.11-cpan-71847e10f99 )