NAME

Footprintless::Util - A utility method package for common functionality in Footprintless

VERSION

version 1.29

SYNOPSIS

use Footprintless::Util qw(
    agent
    clean
    default_command_runner
    dumper
    exit_due_to
    extract
    slurp
    spurt
    temp_dir
);    

my $agent = agent();
my $command_runner = default_command_runner();
my $dumper = dumper();

eval {
    $command_runner->run_or_die('cat /foo/bar');
};
exit_due_to($@) if ($@);    
my $content = slurp('/foo/bar');
spurt('baz', '/foo/bar', append => 1);

DESCRIPTION

This module contains common utility methods used by Footprintless.

FUNCTIONS

agent(%options)

Returns a new agent. By default env_proxy is set. The supported options are:

A hashref for storing cookies. If not supplied, cookies will be ignored.

timeout

The http request timeout.

clean($paths, %options)

Removes all the entries in $paths (must be an array ref). If an entry ends with a / it is assumed to be a directory, and will be recreated.

default_command_runner()

Returns a new instance of the default implementation of Footprintless::CommandRunner.

dumper(@to_dump)

Prints a dump of @to_dump using Data::Dumper with Data::Dumper::Indent set to 1.

dynamic_module_new($module_name, @new_args)

Require's and creates a new instance of $module_name, passing @new_args to the new method.

exit_due_to($reason, $verbose)

If $reason is an instance of Footprintless::CommandRunner::ExecutionException, $reason->exit() will be called. Otherwise, $reason will be printed to STDERR and exit(255) will be called. The $verbose argument will be passed on thusly: $reason->exit($verbose).

extract($archive, %options)

Will extract $archive. Will attempt to use Archive::Extract::Libarchive and if not found, will use Archive::Extract. The available options are:

to

The location to extract to. Defaults to cwd.

type

The type of the archive. If not specified, the type will be inferred by the file extension according to Lib::Archive. The following additional extensions will be inferred as type zip: ear, jar, twbx, war.

factory($entities, %options)

Creates a new Footprintless::Factory. $entities can be either, a hashref, or a Config::Entities object. If a hashref, it will be used to create a new entities object, then passed along with options to the Footprintless::Factory constructor.

invalid_entity($message, $coordinate)

Dies with an instance of Footprintless::InvalidEntityException.

rebase($path, \%rebase)

Replaces a portion of the start of $path. \%rebase must have 2 keys, from and to. The from value will be removed from $path and replaced with the to value.

slurp([$file])

Reads the entire contents of $file in one gulp. If $file is omitted, then it will read STDIN.

spurt($content, $file, %options)

Writes $content to $file. The available options are:

temp_file()

Creates a new temporary file with mode 0600 Returns the new File::Temp object. Uses File::Temp so you can set File::Temp::HIGH for extra safety.

temp_dir()

Creates a new temporary directory with mode 2700. Returns the new File::Temp object. Uses File::Temp so you can set File::Temp::HIGH for extra safety.

terse_dumper(@to_dump)

Prints a dump of @to_dump using Data::Dumper with Data::Dumper::Indent set to 1 and Data::Dumper::Terse set to 1 - this will basically be the same as the dumper() function, except it will not include the variable name ($VAR1 = ).

append

If truthy, $content will be appended to $file instead of overwriting.

AUTHOR

Lucas Theisen <lucastheisen@pastdev.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Lucas Theisen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

SEE ALSO

Please see those modules/websites for more information related to this module.