line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DDG::Meta::ShareDir; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Installing functions for easy access to the module sharedir |
4
|
|
|
|
|
|
|
$DDG::Meta::ShareDir::VERSION = '1016'; |
5
|
11
|
|
|
11
|
|
40
|
use strict; |
|
11
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
251
|
|
6
|
11
|
|
|
11
|
|
38
|
use warnings; |
|
11
|
|
|
|
|
13
|
|
|
11
|
|
|
|
|
238
|
|
7
|
11
|
|
|
11
|
|
34
|
use Carp qw( croak ); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
509
|
|
8
|
11
|
|
|
11
|
|
4046
|
use Module::Data; |
|
11
|
|
|
|
|
44215
|
|
|
11
|
|
|
|
|
375
|
|
9
|
11
|
|
|
11
|
|
4192
|
use Path::Class; |
|
11
|
|
|
|
|
278272
|
|
|
11
|
|
|
|
|
499
|
|
10
|
11
|
|
|
11
|
|
76
|
use Package::Stash; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
248
|
|
11
|
11
|
|
|
11
|
|
4579
|
use File::ShareDir ':ALL'; |
|
11
|
|
|
|
|
45126
|
|
|
11
|
|
|
|
|
5116
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Moo::Role; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %applied; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub apply_keywords { |
19
|
45
|
|
|
45
|
1
|
74
|
my ( $class, $target ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
45
|
50
|
|
|
|
138
|
return if exists $applied{$target}; |
22
|
45
|
|
|
|
|
80
|
$applied{$target} = undef; |
23
|
|
|
|
|
|
|
|
24
|
45
|
|
|
|
|
134
|
my @parts = split('::',$target); |
25
|
45
|
|
|
|
|
53
|
shift @parts; |
26
|
45
|
|
|
|
|
83
|
unshift @parts, 'share'; |
27
|
45
|
|
|
|
|
81
|
my $share_path = join('/',map { s/([a-z])([A-Z])/$1_$2/g; lc; } @parts); |
|
135
|
|
|
|
|
414
|
|
|
135
|
|
|
|
|
269
|
|
28
|
|
|
|
|
|
|
|
29
|
45
|
|
|
|
|
799
|
my $moddata = Module::Data->new($target); |
30
|
45
|
|
|
|
|
18214
|
my $basedir = $moddata->root->parent; |
31
|
|
|
|
|
|
|
|
32
|
45
|
|
|
|
|
125491
|
my $share; |
33
|
|
|
|
|
|
|
|
34
|
45
|
50
|
33
|
|
|
161
|
if ( get_lib($basedir) and get_share($basedir) ) { |
35
|
0
|
|
|
|
|
0
|
my $dir = dir($basedir,$share_path); |
36
|
0
|
0
|
|
|
|
0
|
$share = $dir if -d $dir; |
37
|
|
|
|
|
|
|
} else { |
38
|
45
|
|
|
|
|
1323
|
eval { |
39
|
45
|
|
|
|
|
164
|
my $dir = module_dir($target); |
40
|
0
|
0
|
|
|
|
0
|
$share = dir($dir) if -d $dir; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
45
|
50
|
|
|
|
19010
|
if ($share) { |
45
|
0
|
|
|
|
|
0
|
my $stash = Package::Stash->new($target); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$stash->add_symbol('&share', sub { |
49
|
0
|
0
|
|
0
|
|
0
|
@_ ? -d dir($share,@_) |
|
|
0
|
|
|
|
|
|
50
|
|
|
|
|
|
|
? $share->subdir(@_) |
51
|
|
|
|
|
|
|
: $share->file(@_) |
52
|
|
|
|
|
|
|
: $share |
53
|
0
|
|
|
|
|
0
|
}); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
|
0
|
$stash->add_symbol('&module_share_dir', sub { $share_path }); |
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# apply role |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
Moo::Role->apply_role_to_package($target,'DDG::HasShareDir'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Temporarily add support for both `subdir` and `child` methods |
68
|
|
|
|
|
|
|
# to ensure backwards compatibilty while we upgrade Module::Data |
69
|
|
|
|
|
|
|
# throughout our stack |
70
|
|
|
|
|
|
|
# More info: https://github.com/duckduckgo/duckduckgo/pull/244 |
71
|
|
|
|
|
|
|
sub get_lib { |
72
|
45
|
|
|
45
|
0
|
64
|
my $basedir = shift; |
73
|
45
|
50
|
|
|
|
253
|
return -e $basedir->subdir('lib') if $basedir->can('subdir'); |
74
|
45
|
|
|
|
|
132
|
return -e $basedir->child('lib'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_share { |
78
|
45
|
|
|
45
|
0
|
1525
|
my $basedir = shift; |
79
|
45
|
50
|
|
|
|
155
|
return -e $basedir->subdir('share') if $basedir->can('subdir'); |
80
|
45
|
|
|
|
|
98
|
return -e $basedir->child('share'); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |