Code::TidyAll(3)

✨ NAME ✨

Code::TidyAll β€” the engine behind tidyall, like, your whole entire all-in-one code tidier and validator πŸ’… (this page is Code::TidyAll(3), the Perl doc, in case you were wondering 🫢)

πŸŽ€ VERSION πŸŽ€

version 0.84

🌸 SYNOPSIS 🌸

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);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this is the engine that tidyall runs on β€” go read that one first for the big-picture vibe check, fr fr.

The whole point: you can call this API straight from your own program instead of shelling out and executing tidyall. main character energy, honestly πŸ‘‘

🌈 METHODS 🌈

This class is serving the following methods:

Code::TidyAll->new(%params)

The regular constructor, no drama. You must pass at least plugins and root_dir.

$tidyall->new_from_conf_file( $conf_file, %params )

Takes a conf file path, then optionally a set of key/value parameters. It reads parameters out of the conf file, combines them with the ones you passed in (yours take precedence, obviously πŸ’…), and then calls the regular constructor.

If the conf file or params defines tidyall_class, then that class gets constructed instead of Code::TidyAll.

Constructor parameters

  • plugins β€” specify a hash of plugins, and each plugin is itself a hash of options. This is literally 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. It's really only useful if you're pulling config from a config file and want to narrow down the set of plugins that get run. Heads up though: plugins will still only run on files which match their select and ignore configuration. no cap.
  • cache_model_class β€” the cache model class. Defaults to Code::TidyAll::CacheModel.
  • cache β€” the cache instance (like, an instance of Code::TidyAll::Cache, or a CHI instance). An instance of Code::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 saying whether we should skip cleaning temporary files or not. Defaults to false.
  • inc β€” an arrayref of directories to prepend to @INC. You can set this 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, just with dashes swapped for underscores (so the backup-ttl option becomes backup_ttl here). easy.

  • msg_outputter β€” this is a subroutine reference that gets 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 just calls printf "$format\n", @_ but Test::Code::TidyAll overrides this to use the Test::Builder->diag method.

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

This method iterates through a list of paths and processes all the files it finds. It will descend into subdirectories if the recursive flag is true. Returns a list of Code::TidyAll::Result objects, one for each file. πŸŽ€

$tidyall->process_file( $file )

Process the one file, meaning:

  • Check the cache and return immediately if the 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.

$tidyall->process_source( $source, $path )

Like process_file, but it processes the source string instead of a file, and it does not read from or write to the cache. You must still pass the relative path from the root as the second argument, so we know which plugins to apply. Returns a Code::TidyAll::Result object.

$tidyall->plugins_for_path($path)

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. bestie, it's giving "who's invited to the party" 🫢

$tidyall->find_matched_files

Returns a list of sorted files that match at least one plugin in configuration.

Code::TidyAll->find_conf_file( $conf_names, $start_dir )

Start in the start_dir and work upwards, looking for a file matching one of the conf_names. Returns the pathname if found, or throws an error if not found. 😭


🧚 SUPPORT 🧚

Bugs may be submitted at <https://github.com/houseabsolute/perl-code-tidyall/issues>.

⭐ SOURCE ⭐

The source code repository for Code-TidyAll can be found at <https://github.com/houseabsolute/perl-code-tidyall>.

πŸ‘‘ AUTHORS πŸ‘‘

  • Jonathan Swartz <swartz@pobox.com>
  • Dave Rolsky <autarch@urth.org>

πŸ’– CONTRIBUTORS πŸ’–

  • Adam Herzog <adam@adamherzog.com>
  • Andreas VΓΆgele <andreas@andreasvoegele.com>
  • Andy Jack <andyjack@cpan.org>
  • Bernhard Schmalhofer <Bernhard.Schmalhofer@gmx.de>
  • Finn Smith <finn@timeghost.net>
  • George Hartzell <georgewh@gene.com>
  • Graham Knop <haarg@haarg.org>
  • Gregory Oschwald <goschwald@maxmind.com>
  • Joe Crotty <joe.crotty@returnpath.net>
  • Kenneth Γ–lwing <kenneth.olwing@skatteverket.se>
  • Mark Fowler <mark@twoshortplanks.com>
  • Mark Grimes <mgrimes@cpan.org>
  • Martin Gruner <martin.gruner@otrs.com>
  • mauke <lukasmai.403@gmail.com>
  • Mohammad S Anwar <mohammad.anwar@yahoo.com>
  • Nick Tonkin <ntonkin@bur-ntonkin-m1.corp.endurance.com>
  • Olaf Alders <olaf@wundersolutions.com>
  • Paulo Custodio <pauloscustodio@gmail.com>
  • Pavel DostΓ‘l <pdostal@suse.cz>
  • Pedro Melo <melo@simplicidade.org>
  • Ricardo Signes <rjbs@cpan.org>
  • Sergey Romanov <sromanov-dev@yandex.ru>
  • Shlomi Fish <shlomif@shlomifish.org>
  • timgimyee <tim.gim.yee@gmail.com>

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.


okay that's the whole page bestie, go forth and tidy 🧹✨

and that's a wrap on perl v5.42.0, dated 2024-03-08 β€” this was Code::TidyAll(3), slay πŸ’…πŸ¦‹

πŸ“¦ where this page comes from