DDG/Meta/ShareDir.pm

filter: Statementstmt 84.2% 48 / 57 Branchbran 27.7% 5 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 33.3% 1 / 3 totaltotal 68.4% 65 / 95 SCAR 26.8
CC
11
Cov
69%
apply_keywords
14.0
__ANON__
12.0
get_lib
2.0
CRAP 14.5
« DDG/Block/Words.pm ↑ Summary DDG/Test/Block.pm »
1 package DDG::Meta::ShareDir;
2 11 our $AUTHORITY = 'cpan:DDG';
3 # ABSTRACT: Installing functions for easy access to the module sharedir
4 11 $DDG::Meta::ShareDir::VERSION = '1016';
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Module::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use File::ShareDir ':ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 require Moo::Role;
14  
15  
16 11 my %applied;
17  
18 sub apply_keywords {
19 45 ▶ my ( $class, $target ) = @_;
Subroutine apply_keywords: called CC=7 SCAR=26.4
Pod documented
20  
21 45 ▶ return if exists $applied{$target};
Branch: 1 branch
BranchTrueFalseTotal
if exists $applied{$target} 0 45 45
22 45 $applied{$target} = undef;
23  
24 45 my @parts = split('::',$target);
25 45 shift @parts;
26 45 unshift @parts, 'share';
27 45 my $share_path = join('/',map { s/([a-z])([A-Z])/$1_$2/g; lc; } @parts);
28  
29 45 my $moddata = Module::Data->new($target);
30 45 my $basedir = $moddata->root->parent;
31  
32 45 my $share;
33  
34 45 ▶ if ( get_lib($basedir) and get_share($basedir) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (get_lib($basedir) and get_share($basedir)) { } 0 45 45
Condition33%1/3
get_lib($basedir) and get_share($basedir)
!ll&&!rl&&r
0450
MC/DC0%0/2
get_lib($basedir) and get_share($basedir)
get_lib($basedir) get_share($basedir)
Truth table33%1/3
A and B
A= get_lib($basedir)B= get_share($basedir)
ABresult
0X0
100
111
35 0 my $dir = dir($basedir,$share_path);
36 0 ▶ $share = $dir if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
37 } else {
38 45 eval {
39 45 my $dir = module_dir($target);
40 0 ▶ $share = dir($dir) if -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
if -d $dir 0 0 0
41 }
42 }
43  
44 45 ▶ if ($share) {
Branch: 1 branch
BranchTrueFalseTotal
if ($share) 0 45 45
45 0 my $stash = Package::Stash->new($target);
46  
47  
48 $stash->add_symbol('&share', sub {
49 0 ▶ @_ ? -d dir($share,@_)
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
-d dir($share, @_) ? : 0 0 0
50 ? $share->subdir(@_)
51 : $share->file(@_)
52 : $share
53 0 });
54  
55  
56 0 ▶ $stash->add_symbol('&module_share_dir', sub { $share_path });
Subroutine __ANON__: not called CC=1 SCAR=6.9
57  
58 #
59 # apply role
60 #
61  
62 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 ▶ my $basedir = shift;
Subroutine get_lib: called CC=2 SCAR=7.1
Pod undocumented
73 45 ▶ return -e $basedir->subdir('lib') if $basedir->can('subdir');
Branch: 1 branch
BranchTrueFalseTotal
if $basedir->can("subdir") 0 45 45
74 45 return -e $basedir->child('lib');
75 }
76  
77 sub get_share {
78 45 ▶ my $basedir = shift;
Subroutine get_share: called CC=2 SCAR=7.1
Pod undocumented
79 45 ▶ return -e $basedir->subdir('share') if $basedir->can('subdir');
Branch: 1 branch
BranchTrueFalseTotal
if $basedir->can("subdir") 0 45 45
80 45 return -e $basedir->child('share');
81 }
82 11 1;
83  
84 __END__
« DDG/Block/Words.pm ↑ Summary DDG/Test/Block.pm »