| 1 | package Mojo::Home; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use Mojo::Base 'Mojo::File'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use Mojo::Util qw(class_to_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 89 | ▶ | sub detect { | ||||||||||||||||||||||||||
|
Subroutine
detect: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 7 | 89 | my ($self, $class) = @_; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # Environment variable | ||||||||||||||||||||||||||||
| 10 | 89 | my $home; | |||||||||||||||||||||||||||
| 11 | 89 | ▶ | if ($ENV{MOJO_HOME}) { $home = Mojo::File->new($ENV{MOJO_HOME})->to_array } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Location of the application class (Windows mixes backslash and slash) | ||||||||||||||||||||||||||||
| 14 | ▶ | elsif ($class && (my $path = $INC{my $file = class_to_path $class})) { | |||||||||||||||||||||||||||
|
Condition100%3/3
$class and my $path = $INC{my $file = class_to_path($class)}
MC/DC100%2/2
$class and my $path = $INC{my $file = class_to_path($class)}
$class
my $path = $INC{my $file = class_to_path($class)}
Truth table100%3/3
A and B
A= $classB= my $path = $INC{my $file = class_to_path($class)}
| |||||||||||||||||||||||||||||
| 15 | 68 | $home = Mojo::File->new($path)->to_array; | |||||||||||||||||||||||||||
| 16 | 68 | splice @$home, (my @dummy = split(/\//, $file)) * -1; | |||||||||||||||||||||||||||
| 17 | 68 | ▶ | @$home && $home->[-1] eq $_ && pop @$home for qw(lib blib); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$home and $home->[-1] eq $_
MC/DC100%2/2
@$home and $home->[-1] eq $_
@$home
$home->[-1] eq $_
Truth table100%3/3
A and B
A= @$homeB= $home->[-1] eq $_
| |||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 89 | ▶ | $$self = Mojo::File->new(@$home)->to_abs->to_string if $home; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 89 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | sub rel_file { shift->child(split(/\//, shift)) } | ||||||||||||||||||||||||||
|
Subroutine
rel_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 20 | 1; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =encoding utf8 | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 NAME | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Mojo::Home - Home sweet home | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | use Mojo::Home; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Find and manage the project root directory | ||||||||||||||||||||||||||||
| 39 | my $home = Mojo::Home->new; | ||||||||||||||||||||||||||||
| 40 | $home->detect; | ||||||||||||||||||||||||||||
| 41 | say $home->child('templates', 'layouts', 'default.html.ep'); | ||||||||||||||||||||||||||||
| 42 | say "$home"; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | L<Mojo::Home> is a container for home directories based on L<Mojo::File>. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 METHODS | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | L<Mojo::Home> inherits all methods from L<Mojo::File> and implements the following new ones. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head2 detect | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | $home = $home->detect; | ||||||||||||||||||||||||||||
| 55 | $home = $home->detect('My::App'); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Detect home directory from the value of the C<MOJO_HOME> environment variable or the location of the application class. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head2 rel_file | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $path = $home->rel_file('foo/bar.html'); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Return a new L<Mojo::Home> object relative to the home directory. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 OPERATORS | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | L<Mojo::Home> inherits all overloaded operators from L<Mojo::File>. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||