| 1 | package File::Stubb::Render; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # TODO: '?' sigil for '#' and '$' restricted targets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # TODO: Set '$_' in Perl and shell substs to rendered file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | my $ILLEGAL_PATH_RX = $^O eq 'MSWin32' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ? qr/[<>:"\/\\|?*]/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | : qr/\//; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | my $PATH_SEP = $^O eq 'MSWin32' ? '\\' : '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | our $SUBST_TARGET_NAME_RX = qr/[a-zA-Z0-9_]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my $STDOUT_PATH = '-'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | my $SUBST_TARGET_RX = qr{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | (?<SIGIL> \\? [\?\$!\#])? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | \^\^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | \s* (?<TARGET> .*?) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | \^\^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | }x; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Path substitution targets only contain basic targets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $SUBST_TARGET_PATH_RX = qr{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | \^\^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | \s* (?<TARGET> $SUBST_TARGET_NAME_RX) \s* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | \^\^ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }x; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sub _dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 18 | ▶ | my ($dir, $hidden) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dir: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 18 | ▶ | $hidden //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hidden //= 0
MC/DC0%0/1
$hidden //= 0
$hidden
Truth table50%1/2
A
A= $hidden
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | ▶ | opendir my $dh, $dir | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | or die "Failed to open $dir as a directory: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my @files = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | sort | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 18 | grep { ! /^\.\.?$/ } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | readdir $dh; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 18 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 18 | ▶ | unless ($hidden) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | @files = grep { ! /^\./ } @files; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 18 | return map { File::Spec->catfile($dir, $_) } @files; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub _read_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_json: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | or die "Failed to open $file for reading: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | my $json = do { local $/ = undef; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | my $ref = decode_json($json); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | unless (ref $ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | die "Invalid .stubb.json\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | if ($self->{ Defaults } and ref $ref->{ defaults } eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"Defaults"} and ref $ref->{"defaults"} eq "HASH"
MC/DC50%1/2
$self->{"Defaults"} and ref $ref->{"defaults"} eq "HASH"
$self->{"Defaults"}
ref $ref->{"defaults"} eq "HASH"
Truth table66%2/3
A and B
A= $self->{"Defaults"}B= ref $ref->{"defaults"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | for my $k (keys %{ $ref->{ defaults } }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | $self->{ Subst }{ $k } = $ref->{ defaults }{ $k }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | if (exists $ref->{ render_hidden }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | $self->{ Hidden } = !! $ref->{ render_hidden }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | if (exists $ref->{ follow_symlinks }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | $self->{ FollowLink } = !! $ref->{ follow_symlinks }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | if (exists $ref->{ copy_perms }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | $self->{ CopyPerms } = !! $ref->{ copy_perms }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub _pl_subst { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | my ($self, $pl) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pl_subst: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | local %_ = %{ $self->{ Subst } }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | ▶ | return eval("{ no strict; no warnings; $pl }") // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Condition100%2/2
eval "{ no strict; no warnings; $pl }" // ""
MC/DC100%1/1
eval "{ no strict; no warnings; $pl }" // ""
eval "{ no strict; no warnings; $pl }"
Truth table100%2/2
A
A= eval "{ no strict; no warnings; $pl }"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub _qx_subst { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | my ($self, $qx) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_qx_subst: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | local %ENV = %ENV; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | for my $k (%{ $self->{ Subst } }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 24 | $ENV{ $k } = $self->{ Subst }{ $k }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | my $rt = qx/$qx/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | chomp $rt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | return $rt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | sub _render_link { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my ($self, $link, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_link: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $to = $self->render_path(readlink $link); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | symlink $to, $out | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | or die "Failed to symlink $to to $out: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | sub _render_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14 | ▶ | my ($self, $template, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_dir: called CC=15 SCAR=33.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | ▶ | if ($out eq $STDOUT_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | die "Cannot render directory to stdout\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 14 | my @created; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 14 | ▶ | mkdir $out or die "Failed to mkdir $out: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | ▶ | if ($self->{ CopyPerms }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | chmod((stat($template))[2] & 0777, $out); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 14 | push @created, $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | for my $f (_dir($template, $self->{ Hidden })) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 17 | my $bn = basename($f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 17 | ▶ | next if $bn eq '.stubb.json'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 15 | my $o = File::Spec->catfile( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $out, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $self->render_path($bn) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 15 | my @c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 15 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 15 | ▶ | if (-d $f) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | @c = $self->_render_dir($f, $o); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ▶ | } elsif (!$self->{ FollowLink } and -l $f) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $self->{"FollowLink"} and -l $f
MC/DC0%0/2
not $self->{"FollowLink"} and -l $f
not $self->{"FollowLink"}
-l $f
Truth table66%2/3
not(A) and B
A= not $self->{"FollowLink"}B= -l $f
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | @c = $self->_render_link($f, $o); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | @c = $self->_render_file($f, $o); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 15 | ▶ | if ($@ ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | for my $del (reverse @created) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (-d $del) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | rmdir $del or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } elsif (-f $del) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | unlink $del or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | die $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 15 | push @created, @c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 14 | return @created; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | sub _render_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 23 | ▶ | my ($self, $template, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_file: called CC=23 SCAR=32.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 23 | ▶ | open my $rh, '<', $template | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | or die "Failed to open $template for reading: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 23 | binmode $rh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 23 | my $wh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 23 | ▶ | if ($out eq $STDOUT_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $wh = *STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 23 | ▶ | open $wh, '>', $out | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | or die "Failed to open $out for writing: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 23 | binmode $wh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 23 | ▶ | while (my $l = readline $rh) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 60 | $l =~ s{($SUBST_TARGET_RX)}{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 85 | my $m = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 85 | my %c = %+; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 85 | my $repl = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 85 | ▶ | if (defined $c{ SIGIL } and $c{ SIGIL } =~ /^\\/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $c{"SIGIL"} and $c{"SIGIL"} =~ /^\\/u
MC/DC100%2/2
defined $c{"SIGIL"} and $c{"SIGIL"} =~ /^\\/u
defined $c{"SIGIL"}
$c{"SIGIL"} =~ /^\\/u
Truth table100%3/3
A and B
A= defined $c{"SIGIL"}B= $c{"SIGIL"} =~ /^\\/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Copy escaped sigil | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 12 | $repl .= substr $c{ SIGIL }, 1, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 12 | $m = substr $m, length $c{ SIGIL }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 85 | ▶ | if (not defined $c{ SIGIL } or $c{ SIGIL } =~ /^\\/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
not defined $c{"SIGIL"} or $c{"SIGIL"} =~ /^\\/u
MC/DC100%2/2
not defined $c{"SIGIL"} or $c{"SIGIL"} =~ /^\\/u
not defined $c{"SIGIL"}
$c{"SIGIL"} =~ /^\\/u
Truth table100%3/3
not(A) or B
A= not defined $c{"SIGIL"}B= $c{"SIGIL"} =~ /^\\/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 54 | my ($targ, $def) = split /\s*\/\/\s*/, $c{ TARGET }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 54 | ▶ | if ($targ !~ /^$SUBST_TARGET_NAME_RX$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $repl = $m; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | $repl .= exists $self->{ Subst }{ $targ } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 54 | ▶ | ? $self->{ Subst }{ $targ } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$def // $m
MC/DC0%0/2
$def // $m
$def
$m
Truth table66%2/3
A // B
A= $defB= $m
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | : $def // $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } elsif ($c{ SIGIL } eq '?') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | if ($c{ TARGET } !~ /^$SUBST_TARGET_NAME_RX$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $repl = $m; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $repl = exists $self->{ Subst }{ $c{ TARGET } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ? $self->{ Subst }{ $c{ TARGET } } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | ▶ | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } elsif ($c{ SIGIL } eq '$') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | $repl = $self->{ Restricted } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ? $m | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 12 | ▶ | : $self->_pl_subst($c{ TARGET }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } elsif ($c{ SIGIL } eq '#') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $repl = $self->{ Restricted } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ? $m | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 8 | ▶ | : $self->_qx_subst($c{ TARGET }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } elsif ($c{ SIGIL } eq '!') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | $repl = substr $m, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 85 | $repl; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | }ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 60 | print { $wh } $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 23 | close $rh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 23 | ▶ | close $wh unless $out eq $STDOUT_PATH; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 23 | ▶ | if ($self->{ CopyPerms } and $out ne $STDOUT_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"CopyPerms"} and $out ne $STDOUT_PATH
MC/DC50%1/2
$self->{"CopyPerms"} and $out ne $STDOUT_PATH
$self->{"CopyPerms"}
$out ne $STDOUT_PATH
Truth table66%2/3
A and B
A= $self->{"CopyPerms"}B= $out ne $STDOUT_PATH
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | chmod((stat($template))[2] & 0777, $out); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | sub _path_targets { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_path_targets: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | my %targ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | ▶ | while (my $m = $path =~ m/($SUBST_TARGET_PATH_RX)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 6 | $targ{ $+{ TARGET } } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | return sort keys %targ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sub _file_targets { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 13 | ▶ | my ($self, $template, $targets) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_file_targets: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 13 | ▶ | open my $fh, '<', $template | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | or die "Failed to open $template for reading: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 13 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 13 | ▶ | while (my $l = readline $fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 36 | ▶ | while (my $m = $l =~ m/($SUBST_TARGET_RX)/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 45 | my %c = %+; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 45 | ▶ | if (not defined $c{ SIGIL } or $c{ SIGIL } eq '?' or $c{ SIGIL } =~ /^\\/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
not defined $c{"SIGIL"} or $c{"SIGIL"} eq "?" or $c{"SIGIL"} =~ /^\\/u
not defined $c{"SIGIL"} or $c{"SIGIL"} eq "?"
MC/DC100%3/3
not defined $c{"SIGIL"} or $c{"SIGIL"} eq "?" or $c{"SIGIL"} =~ /^\\/u
not defined $c{"SIGIL"}
$c{"SIGIL"} eq "?"
$c{"SIGIL"} =~ /^\\/u
Truth table100%4/4
not(A) or B or C
A= not defined $c{"SIGIL"}B= $c{"SIGIL"} eq "?"C= $c{"SIGIL"} =~ /^\\/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 24 | my $t = $c{ TARGET } =~ s/\s*\/\/.*$//r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 24 | ▶ | next unless $t =~ /^$SUBST_TARGET_NAME_RX$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 24 | $targets->{ basic }{ $t } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ▶ | } elsif ($c{ SIGIL } eq '$' and not $self->{ Restricted }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c{"SIGIL"} eq "\$" and not $self->{"Restricted"}
MC/DC100%2/2
$c{"SIGIL"} eq "\$" and not $self->{"Restricted"}
$c{"SIGIL"} eq "\$"
not $self->{"Restricted"}
Truth table100%3/3
A and not(B)
A= $c{"SIGIL"} eq "\$"B= not $self->{"Restricted"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4 | push @{ $targets->{ perl } }, $c{ TARGET }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ▶ | } elsif ($c{ SIGIL } eq '#' and not $self->{ Restricted }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c{"SIGIL"} eq "#" and not $self->{"Restricted"}
MC/DC100%2/2
$c{"SIGIL"} eq "#" and not $self->{"Restricted"}
$c{"SIGIL"} eq "#"
not $self->{"Restricted"}
Truth table100%3/3
A and not(B)
A= $c{"SIGIL"} eq "#"B= not $self->{"Restricted"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | push @{ $targets->{ shell } }, $c{ TARGET }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 13 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 13 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | sub _dir_targets { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | ▶ | my ($self, $template, $targets) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dir_targets: called CC=8 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 4 | for my $f (_dir($template, $self->{ Hidden })) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 7 | my $bn = basename($f); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 7 | ▶ | next if $bn eq '.stubb.json'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | for my $t ($self->_path_targets($bn)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 6 | $targets->{ basic }{ $t } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | ▶ | if (-l $f and !$self->{ FollowLink }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
-l $f and not $self->{"FollowLink"}
MC/DC0%0/2
-l $f and not $self->{"FollowLink"}
-l $f
not $self->{"FollowLink"}
Truth table33%1/3
A and not(B)
A= -l $fB= not $self->{"FollowLink"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | for my $t ($self->_path_targets(readlink $f)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $targets->{ basic }{ $t } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } elsif (-d $f) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | $self->_dir_targets($f, $targets); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | $self->_file_targets($f, $targets); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 23 | ▶ | my ($class, %param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | Template => $param{ template }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 23 | Subst => {}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | Hidden => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | FollowLink => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | CopyPerms => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | Defaults => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | IgnoreConf => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | Restricted => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 23 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 23 | my $json = File::Spec->catfile($self->{ Template }, '.stubb.json'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 23 | ▶ | if (defined $param{ ignore_config }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | $self->{ IgnoreConf } = !! $param{ ignore_config }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 23 | ▶ | if (defined $param{ defaults }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2 | $self->{ Defaults } = !! $param{ defaults }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 23 | ▶ | if (-f $json and !$self->{ IgnoreConf }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-f $json and not $self->{"IgnoreConf"}
MC/DC100%2/2
-f $json and not $self->{"IgnoreConf"}
-f $json
not $self->{"IgnoreConf"}
Truth table100%3/3
A and not(B)
A= -f $jsonB= not $self->{"IgnoreConf"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4 | $self->_read_json($json); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 23 | ▶ | if (defined $param{ subst }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 11 | $self->{ Subst } = $param{ subst }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 23 | ▶ | if (defined $param{ render_hidden }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | $self->{ Hidden } = !! $param{ render_hidden }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 23 | ▶ | if (defined $param{ follow_symlinks }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | $self->{ FollowLink } = !! $param{ follow_symlinks }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 23 | ▶ | if (defined $param{ copy_perms }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | $self->{ CopyPerms } = !! $param{ copy_perms }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 23 | ▶ | if (defined $param{ restricted }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 3 | $self->{ Restricted } = !! $param{ restricted }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 23 | for my $k (keys %{ $self->{ Subst } }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 36 | ▶ | unless ($k =~ /^$SUBST_TARGET_NAME_RX$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | die "'$k' is not a valid substitution target\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 23 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 22 | ▶ | my ($self, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 22 | $out = $self->render_path($out); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | my @created = -d $self->{ Template } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | ? $self->_render_dir($self->{ Template }, $out) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 22 | ▶ | : $self->_render_file($self->{ Template }, $out); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 22 | return @created; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | sub targets { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 11 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
targets: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 11 | my $targets = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | basic => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | perl => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | shell => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 11 | ▶ | if (-d $self->{ Template }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | $self->_dir_targets($self->{ Template }, $targets); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 9 | $self->_file_targets($self->{ Template }, $targets); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 11 | $targets->{ basic } = [ sort keys %{ $targets->{ basic } } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 11 | return $targets; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | sub render_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 38 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_path: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 38 | my @parts = split /\Q$PATH_SEP\E/, $path; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 38 | for (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 91 | s{($SUBST_TARGET_PATH_RX)}{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 18 | my $m = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 18 | my %c = %+; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 18 | my $repl = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 18 | ▶ | if (not exists $self->{ Subst }{ $c{ TARGET } }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 4 | $repl = $m; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 14 | ▶ | if ($self->{ Subst }{ $c{ TARGET } } =~ $ILLEGAL_PATH_RX) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | die "'$c{ TARGET }' path substitution would contain illegal path characters\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 14 | $repl = $self->{ Subst }{ $c{ TARGET } }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 18 | $repl; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | }ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 38 | return File::Spec->catfile(@parts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | sub template { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | return $self->{ Template }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | sub subst { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subst: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 4 | return $self->{ Subst }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | sub set_subst { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | my ($self, $subst) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_subst: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | unless (ref $subst eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | die "\$subst must be a hash ref"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $self->{ Subst } = $subst; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | sub hidden { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hidden: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | return $self->{ Hidden }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | sub set_hidden { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | my ($self, $hidden) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_hidden: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $self->{ Hidden } = !! $hidden; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | sub follow_symlinks { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
follow_symlinks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | return $self->{ FollowLink }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | sub set_follow_symlinks { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my ($self, $follow) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_follow_symlinks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $self->{ FollowLink } = !! $follow; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | sub copy_perms { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy_perms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 4 | return $self->{ CopyPerms }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | sub set_copy_perms { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | my ($self, $copy) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_copy_perms: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $self->{ CopyPerms } = !! $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | sub restricted { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restricted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 3 | return $self->{ Restricted }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | sub set_restricted { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | my ($self, $rest) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_restricted: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $self->{ Restricted } = !! $rest; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | sub defaults { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | return $self->{ Defaults }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | sub ignore_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ignore_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | return $self->{ IgnoreConf }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | File::Stubb::Render - Stubb template rendering class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | =head1 USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | use File::Stubb::Render; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | my $render = File::Stubb::Render->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | template => '/path/to/template', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | subst => { one => 1, two => 2 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | my @created = $render->render('/path/to/output'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | B<File::Stubb::Render> is a module that provides an object-oriented interface | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | to L<stubb>'s template rendering routines. This is a private module for L<stubb>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | For user documentation, consult the L<stubb> manual. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | =item $render = File::Stubb::Render->new(%params) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | Creates a new B<File::Stubb::Render> object from C<%params>. The following are | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | valid parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | =item template | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | Path to template file. Required | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | =item subst | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | Hash ref of substitution parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | =item render_hidden | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | Boolean determining whether to render hidden files from a template directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | Defaults to false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | =item follow_symlinks | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | Boolean determining whether to render the file symlinks point to, or to copy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | the symlinks themselves in template directories. Defaults to true. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | =item copy_perms | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | Boolean determining whether to copy the permissions of a template file when | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | rendering. Defaults to false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | =item restricted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | Boolean determining whether to render files in a "restricted" mode. When | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | restricted, Perl targets and shell targets will not be rendered and left as-is. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | =item defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | Boolean determining whether to use any default substitution parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | provided by a template's F<.stubb.json>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | =item ignore_config | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | Boolean determining whether a template's config file should be ignored during | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | initialization or not. Defaults to false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | =item @created = $render->render($output) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | Render template to C<$output>. Returns a list of created files. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | For documentation on how L<stubb> renders files, consult the L<stubb> manual. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | =item $targets = $render->targets() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | Returns a hash ref list of targets in the object's template. The hash ref will | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | look something like this: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | basic => [ ... ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | perl => [ ... ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | shell => [ ... ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | =item $new = $render->render_path($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | Renders C<$path> as a path name. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | =item $template = $render->template() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | Get the path to C<$render>'s template file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | =item $subst = $render->subst() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | =item $render->set_subst($subst) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | Getter/setter for C<$render>'s substitution parameter hash ref. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | =item $hidden = $render->hidden() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | =item $render->set_hidden($hidden) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | Getter/setter for C<$render>'s render hidden files flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | =item $follow = $render->follow_symlinks() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | =item $render->set_follow_symlinks($follow) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | Getter/setter for C<$render>'s follow symlinks flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | =item $copy = $render->copy_perms | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | =item $render->set_copy_perms($copy) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | Getter/setter for C<$render>'s copy perms flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | =item $rest = $render->restricted | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | =item $render->set_restricted($rest) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | Getter/setter for C<$render>'s restricted flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | =item $def = $render->defaults() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | Getter for C<$render>'s defaults flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | =item $ign = $render->ignore_config() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | Getter for C<$render>'s ignore_config flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | Written by Samuel Young, E<lt>samyoung12788@gmail.comE<gt>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | This project's source can be found on its | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | L<Codeberg page|https://codeberg.org/1-1sam/stubb.git>. Comments and pull | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | requests are welcome! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | Copyright (C) 2025 Samuel Young | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | L<stubb> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # vim: expandtab shiftwidth=4 | ||||||||||||||||||||||||||||||||||||||||||||||||||