line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Home; |
2
|
50
|
|
|
50
|
|
394
|
use Mojo::Base 'Mojo::File'; |
|
50
|
|
|
|
|
113
|
|
|
50
|
|
|
|
|
385
|
|
3
|
|
|
|
|
|
|
|
4
|
50
|
|
|
50
|
|
377
|
use Mojo::Util qw(class_to_path); |
|
50
|
|
|
|
|
173
|
|
|
50
|
|
|
|
|
19824
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub detect { |
7
|
111
|
|
|
111
|
1
|
428
|
my ($self, $class) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Environment variable |
10
|
111
|
|
|
|
|
246
|
my $home; |
11
|
111
|
100
|
100
|
|
|
723
|
if ($ENV{MOJO_HOME}) { $home = Mojo::File->new($ENV{MOJO_HOME})->to_array } |
|
58
|
100
|
|
|
|
298
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Location of the application class (Windows mixes backslash and slash) |
14
|
|
|
|
|
|
|
elsif ($class && (my $path = $INC{my $file = class_to_path $class})) { |
15
|
49
|
|
|
|
|
277
|
$home = Mojo::File->new($path)->to_array; |
16
|
49
|
|
|
|
|
780
|
splice @$home, (my @dummy = split(/\//, $file)) * -1; |
17
|
49
|
|
100
|
|
|
520
|
@$home && $home->[-1] eq $_ && pop @$home for qw(lib blib); |
|
|
|
66
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
111
|
100
|
|
|
|
1189
|
$$self = Mojo::File->new(@$home)->to_abs->to_string if $home; |
21
|
111
|
|
|
|
|
846
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
1
|
26
|
sub rel_file { shift->child(split(/\//, shift)) } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
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 is a container for home directories based on L. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
L inherits all methods from L 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 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 object relative to the home directory. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 OPERATORS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L inherits all overloaded operators from L. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L, L, L. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |