CLI/Package.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 64.2% 9 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 91.4% 64 / 70 CC 9 SCAR 12.0
CC
9
Cov
90%
build
5.1
__ANON__
4.1
add_dir
2.0
CRAP 3.3
« CLI/Git.pm ↑ Summary CLI/Command/Build.pm »
1 # PODNAME: Luv::CLI::Package
2 # ABSTRACT: packages a luv project into a .love file
3  
4 2 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Archive::Zip qw(:ERROR_CODES);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 class Luv::CLI::Package;
11  
12 2 field $manifest : param;
13  
14 1 ▶method build () {
Subroutine build: called CC=5 SCAR=16.2
Pod documented
15 1 my $output_path = $manifest->build_dir . '/' . $manifest->output_name;
16  
17 1 my $zip = Archive::Zip->new;
18  
19 1 for my $file ( 'main.lua', 'conf.lua' ) {
20 2 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 1 1 2
21 1 $zip->addFile( $file, $file );
22 }
23 }
24  
25 1 $self->add_dir( $zip, $manifest->source_dir, $manifest->source_dir );
26 1 $self->add_dir( $zip, $manifest->library_dir, $manifest->library_dir );
27 1 $self->add_dir( $zip, $manifest->assets_dir, $manifest->assets_dir );
28  
29 1 ▶ File::Path::make_path( $manifest->build_dir )
Branch: 1 branch
BranchTrueFalseTotal
unless -d $manifest->build_dir 0 1 1
30 unless -d $manifest->build_dir;
31  
32 1 ▶ unless ( $zip->writeToFileNamed($output_path) == Archive::Zip::AZ_OK() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zip->writeToFileNamed($output_path) == 0) 0 1 1
33 0 die "Failed to write $output_path\n";
34 }
35  
36 1 return $output_path;
37 2 }
38  
39 3 ▶method add_dir ( $zip, $dir, $zip_prefix ) {
Subroutine add_dir: called CC=2 SCAR=7.0
Pod documented
40 3 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 3 3
41  
42 3 my $build_dir = $manifest->build_dir;
43  
44 File::Find::find(
45 4 ▶ { wanted => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
46 4 ▶ return unless -f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 3 1 4
47 1 my $rel = $File::Find::name;
48  
49 1 ▶ return if $rel =~ m{^\Q$build_dir\E(/|$)};
Branch: 1 branch
BranchTrueFalseTotal
if $rel =~ m[^\Q$build_dir\E(/|$)]u 0 1 1
50  
51 1 $rel =~ s{^\Q$dir\E/?}{};
52 1 ▶ my $zip_path = $zip_prefix ? "$zip_prefix/$rel" : $rel;
Branch: 1 branch
BranchTrueFalseTotal
$zip_prefix ? : 1 0 1
53 1 $zip->addFile( $_, $zip_path );
54 },
55 3 no_chdir => 1,
56 },
57 $dir
58 );
59  
60 3 return;
61 2 }
62  
63 2 1;
64  
65 __END__
« CLI/Git.pm ↑ Summary CLI/Command/Build.pm »