Code::TidyAll - Engine for tidyall, your all-in-one code tidier and validator
version 0.84
use Code::TidyAll;
my $ct = Code::TidyAll->new_from_conf_file(
'/path/to/conf/file',
...
);
# or
my $ct = Code::TidyAll->new(
root_dir => '/path/to/root',
plugins => {
perltidy => {
select => 'lib/**/*.(pl|pm)',
argv => '-noll -it=2',
},
...
}
);
# then...
$ct->process_paths($file1, $file2);
This is the engine used by tidyall - read that first to get an overview.
You can call this API from your own program instead of executing tidyall
.
This class offers the following methods:
The regular constructor. Must pass at least plugins and root_dir.
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 tidyall_class, then that class is
constructed instead of Code::TidyAll
.
-
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.
-
selected_plugins
An arrayref of plugins to be used. This overrides the
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
select
andignore
configuration. -
cache_model_class
The cache model class. Defaults to
Code::TidyAll::CacheModel
-
cache
The cache instance (e.g. an instance of
Code::TidyAll::Cache
or aCHI
instance.) An instance ofCode::TidyAll::Cache
is automatically instantiated by default. -
backup_ttl
-
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.
-
no_cleanup
A boolean indicating if we should skip cleaning temporary files or not. Defaults to false.
-
inc
An arrayref of directories to prepend to
@INC
. This can be set via the command-line as-I
, but you can also set it in a config file.This affects both loading and running plugins.
-
data_dir
-
iterations
-
mode
-
no_backups
-
no_cache
-
output_suffix
-
quiet
-
root_dir
-
ignore
-
verbose
These options are the same as the equivalent
tidyall
command-line options, replacing dashes with underscore (e.g. thebackup-ttl
option becomesbackup_ttl
here). -
msg_outputter
This is a subroutine reference that is called whenever a message needs to be printed in some way. The sub receives a
sprintf()
format string followed by one or more parameters. The default sub used simply callsprintf "$format\n", @_
but Test::Code::TidyAll overrides this to use theTest::Builder->diag
method.
This method iterates through a list of paths, processing all the files it
finds. It will descend into subdirectories if recursive
flag is true.
Returns a list of Code::TidyAll::Result objects, one for each file.
Process the one file, meaning:
- Check the cache and return immediately if file has not changed.
- Apply appropriate matching plugins.
- Print success or failure result to STDOUT, depending on quiet/verbose settings.
- Write to the cache if caching is enabled.
- Return a Code::TidyAll::Result object.
Like process_file
, but process the source string instead of a file, and
does not read from or write to the cache. You must still pass the relative
path from the root as the second argument, so that we know which plugins to
apply. Returns a Code::TidyAll::Result object.
Given a relative path from the root, returns a list of Code::TidyAll::Plugin objects that apply to it, or an empty list if no plugins apply.
Returns a list of sorted files that match at least one plugin in configuration.
Start in the start_dir and work upwards, looking for a file matching one of the conf_names. Returns the pathname if found or throw an error if not found.
Bugs may be submitted at https://github.com/houseabsolute/perl-code-tidyall/issues.
The source code repository for Code-TidyAll can be found at https://github.com/houseabsolute/perl-code-tidyall.
- Jonathan Swartz [email protected]
- Dave Rolsky [email protected]
- Adam Herzog [email protected]
- Andreas Vögele [email protected]
- Andy Jack [email protected]
- Bernhard Schmalhofer [email protected]
- Finn Smith [email protected]
- George Hartzell [email protected]
- Graham Knop [email protected]
- Gregory Oschwald [email protected]
- Joe Crotty [email protected]
- Kenneth Ölwing [email protected]
- Mark Fowler [email protected]
- Mark Grimes [email protected]
- Martin Gruner [email protected]
- mauke [email protected]
- Mohammad S Anwar [email protected]
- Nick Tonkin [email protected]
- Olaf Alders [email protected]
- Paulo Custodio [email protected]
- Pavel Dostál [email protected]
- Pedro Melo [email protected]
- Ricardo Signes [email protected]
- Sergey Romanov [email protected]
- Shlomi Fish [email protected]
- timgimyee [email protected]
This software is copyright (c) 2011 - 2023 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
The full text of the license can be found in the
LICENSE
file included with this distribution.