line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::File::Share; |
2
|
1
|
|
|
1
|
|
1189
|
use Mojo::Base -strict; |
|
1
|
|
|
|
|
235733
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
131
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
6
|
use Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
489
|
use File::ShareDir (); |
|
1
|
|
|
|
|
22306
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
7
|
use File::Spec (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
7
|
1
|
|
|
1
|
|
457
|
use Mojo::File 'path'; |
|
1
|
|
|
|
|
28510
|
|
|
1
|
|
|
|
|
545
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(dist_dir dist_file); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub dist_dir { |
14
|
0
|
|
0
|
0
|
1
|
|
my $dist = shift // _get_caller_dist(); |
15
|
0
|
|
|
|
|
|
my $inc = _get_inc_from_dist($dist); |
16
|
0
|
|
|
|
|
|
my $path = _get_path_from_inc($inc); |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
0
|
|
|
|
if ($path and |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
19
|
|
|
|
|
|
|
-d $path->dirname->sibling('lib') and |
20
|
|
|
|
|
|
|
-d -r $path->dirname->sibling('share')) { |
21
|
0
|
|
|
|
|
|
return $path->dirname->sibling('share')->realpath; |
22
|
|
|
|
|
|
|
} elsif (-e path('lib', $inc) and -d -r path('share')) { |
23
|
0
|
|
|
|
|
|
return path('share')->realpath; |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
|
return path(File::ShareDir::dist_dir($dist))->realpath; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub dist_file { |
30
|
0
|
0
|
|
0
|
1
|
|
my $dist_file = dist_dir(@_ > 1 ? shift : _get_caller_dist())->child(@_)->realpath; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
-f $dist_file or Carp::croak "File '$dist_file': No such file"; |
33
|
0
|
0
|
|
|
|
|
-r $dist_file or Carp::croak "File '$dist_file': No read permission"; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $dist_file; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _get_caller_dist { |
39
|
0
|
|
|
0
|
|
|
my ($package) = caller(1); |
40
|
0
|
|
|
|
|
|
$package =~ s/::/-/g; |
41
|
0
|
|
|
|
|
|
return $package; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_inc_from_dist { |
45
|
0
|
|
|
0
|
|
|
my ($dist) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $file_separator = File::Spec->catfile('', ''); |
48
|
0
|
|
|
|
|
|
(my $inc = $dist) =~ s!(-|::)!$file_separator!g; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return "$inc.pm"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _get_path_from_inc { |
54
|
0
|
|
|
0
|
|
|
my ($inc) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
my $path = $INC{$inc} // ''; |
57
|
0
|
|
|
|
|
|
$path =~ s/$inc$//; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return path($path); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |