Enbld/Target/Symlink.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 92.0% 69 / 75 SCAR 25.7
CC
13
Cov
94%
create_symlink
8.1
delete_symlink
6.0
BEGIN
1.0
CRAP 13.0
« Enbld/Config.pm ↑ Summary Enbld/Command/Install.pm »
1 package Enbld::Target::Symlink;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Path qw/make_path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 require Enbld::Home;
10  
11  
12 # directory list for symbolic link
13 2 our $dir_list = {
14 'bin' => {
15 'dir' => 'bin',
16 'omit' => undef,
17 },
18  
19 'sbin' => {
20 'dir' => 'sbin',
21 'omit' => undef,
22 },
23  
24 'lib' => {
25 'dir' => 'lib',
26 'omit' => [ 'pkgconfig', 'perl5' ],
27 },
28
29 'pkgconfig' => {
30 'dir' => File::Spec->catdir( 'lib', 'pkgconfig' ),
31 'omit' => undef,
32 },
33
34 'include' => {
35 'dir' => 'include',
36 'omit' => undef,
37 },
38  
39 'script' => {
40 'dir' => 'script',
41 'omit' => undef,
42 },
43  
44 'support-files' => {
45 'dir' => 'support-files',
46 'omit' => undef,
47 },
48  
49 'man-man1' => {
50 'dir' => File::Spec->catdir( 'man', 'man1' ),
51 'omit' => undef,
52 },
53  
54 'man-man3' => {
55 'dir' => File::Spec->catdir( 'man', 'man3' ),
56 'omit' => undef,
57 },
58  
59 'share-man1' => {
60 'dir' => File::Spec->catdir( 'share', 'man', 'man1' ),
61 'omit' => undef,
62 },
63  
64 'share-man3' => {
65 'dir' => File::Spec->catdir( 'share', 'man', 'man3' ),
66 'omit' => undef,
67 },
68  
69 'share' => {
70 'dir' => 'share',
71 'omit' => [ 'emacs', 'info', 'man', 'doc', 'aclocal' ],
72 },
73  
74 'doc' => {
75 'dir' => File::Spec->catdir( 'share', 'doc' ),
76 'omit' => undef,
77 },
78  
79 'site-lisp' => {
80 'dir' => File::Spec->catdir( 'share', 'emacs', 'site-lisp' ),
81 'omit' => undef,
82 },
83  
84 'aclocal' => {
85 'dir' => File::Spec->catdir( 'share', 'aclocal' ),
86 'omit' => undef,
87 },
88 };
89  
90 sub delete_symlink {
91 28 ▶ my ( $pkg, $old_depository ) = @_;
Subroutine delete_symlink: called CC=6 SCAR=17.9
Pod undocumented
92  
93 28 foreach my $dir ( sort keys %{ $dir_list } ) {
94 my $installed = File::Spec->catdir(
95 Enbld::Home->home,
96 $dir_list->{$dir}{dir}
97 420 );
98  
99 420 ▶ next unless ( -d $installed );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $installed 412 8 420
100
101 8 opendir( my $dh, $installed );
102 8 my @list = grep { !/^\.{1,2}$/ } readdir $dh;
103 8 closedir $dh;
104  
105 8 chdir $installed;
106
107 8 foreach my $file ( @list ) {
108 8 ▶ next unless ( -l $file );
Branch: 1 branch
BranchTrueFalseTotal
unless -l $file 0 8 8
109  
110 8 my $link = readlink( $file );
111
112 8 ▶ if ( index( $link, $old_depository ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($link, $old_depository) == 0) 5 3 8
113 5 unlink $file;
114 }
115 }
116 }
117 }
118  
119 sub create_symlink {
120 27 ▶ my ( $pkg, $new_depository ) = @_;
Subroutine create_symlink: called CC=8 SCAR=20.9
Pod undocumented
121  
122 27 foreach my $dir ( sort keys %{$dir_list} ) {
123 my $link_from_path =
124 405 File::Spec->catdir( $new_depository, $dir_list->{$dir}{dir} );
125  
126 405 ▶ next unless ( -d $link_from_path );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $link_from_path 378 27 405
127
128 27 opendir( my $dh, $link_from_path );
129 27 my @list = grep { !/^\.{1,2}$/ } readdir $dh;
130 27 closedir $dh;
131
132 my $link_to_path = File::Spec->catdir(
133 Enbld::Home->home,
134 $dir_list->{$dir}{dir}
135 27 );
136
137 27 ▶ unless ( -d $link_to_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $link_to_path) 20 7 27
138 20 make_path( $link_to_path );
139 }
140  
141 27 foreach my $file ( @list ) {
142 27 ▶ next if ( grep {/^$file$/ } @{$dir_list->{$dir}{omit}} );
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^$file$/;} @{$$Enbld::Target::Symlink::dir_list{$dir}{"omit"};} 0 27 27
143
144 27 my $symlink = File::Spec->catfile( $link_to_path, $file );
145
146 27 ▶ if ( -l $symlink ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $symlink) 3 24 27
147 3 unlink $symlink;
148 }
149
150 27 ▶ unless ( -e $symlink ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $symlink) 27 0 27
151 27 symlink File::Spec->catfile( $link_from_path, $file ), $symlink;
152 }
153 }
154 }
155 }
156  
157  
158 2 1;
« Enbld/Config.pm ↑ Summary Enbld/Command/Install.pm »