The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::Home - Detect And Access The Project Root Directory In Mojo

SYNOPSIS

    use Mojo::Home;

DESCRIPTION

Mojo::Home is a container for home directories. Functionality includes locating the home directory and portable path handling.

ATTRIBUTES

app_class

    my $class = $home->app_class;
    $home     = $home->app_class('Foo::Bar');

Returns the Mojo applications class name if called without arguments. Returns the invocant if called with arguments.

parts

    my $parts = $home->parts;
    $home     = $home->parts([qw/foo bar baz/]);

Returns an arrayref containing the parts of the projects root directory if called without arguments. Returns the invocant if called with arguments.

METHODS

Mojo::Home inherits all methods from Mojo::Base and implements the following new ones.

new

    my $home = Mojo::Home->new;
    my $home = Mojo::Home->new('/foo/bar/baz');

Returns a new Mojo::Home object, used to find the root directory of the project.

detect

    $home = $home->detect;
    $home = $home->detect('My::App');

Returns the invocant and detects the path to the root of the Mojo project. $ENV{MOJO_HOME} is used as the location if available. Autodetection based on the class name is used as a fallback.

executable

    my $path = $home->executable;

Returns the path to the Mojo executable in the bin directory of your project, it will either be named after your project, or mojo.

lib_dir

    my $path = $home->lib_dir;

Returns the path to the lib directory of the project if it exists, or undef otherwise.

parse

    $home = $home->parse('/foo/bar');

Returns the invocant and splits the given path into parts.

rel_dir

    my $path = $home->rel_dir('foo/bar');

Returns an absolute directory path based on the projects root directory. Note that the UNIX style / is used as separator on all platforms.

rel_file

    my $path = $home->rel_file('foo/bar.html');

Returns an absolute file path based on the projects root directory. Note that the UNIX style / is used as separator on all platforms.

to_string

    my $string = $home->to_string;
    my $string = "$home";

Return the path to projects root directory.