lib/Panotools/Makefile/Variable.pm

filter: Statementstmt 91.1% 41 / 45 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 73.9% 51 / 69 CC 4 SCAR 5.2
CC
4
Cov
85%
new
2.1
Name
2.0
Assemble
2.0
CRAP 1.7
« lib/Panotools/Matrix.pm ↑ Summary lib/Panotools/Script/Line/Mask.pm »
1 package Panotools::Makefile::Variable;
2  
3 =head1 NAME
4  
5 Panotools::Makefile::Variable - Assemble Makefile Variable definitions
6  
7 =head1 SYNOPSIS
8  
9 Simple interface for generating Makefile syntax
10  
11 =head1 DESCRIPTION
12  
13 Writing Makefiles directly from perl scripts with print and "\t" etc... is
14 prone to error, this library provides a simple perl interface for assembling
15 Makefiles.
16  
17 =cut
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Panotools::Makefile::Utils qw/quotetarget quoteprerequisite quoteshell/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 =head1 USAGE
25  
26 $var = new Panotools::Makefile::Variable;
27  
28 ..or define the 'variable name' at the same time:
29  
30 $var = new Panotools::Makefile::Variable ('USERS');
31  
32 ..or define the name and values at the same time:
33  
34 $var = new Panotools::Makefile::Variable ('USERS', 'Andy Pandy');
35  
36 =cut
37  
38 sub new
39 2 ▶{
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
40 2 my $class = shift;
41 2 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
42 2 my $self = bless {name => shift, value => [@_]}, $class;
43 2 return $self;
44 }
45  
46 =pod
47  
48 Set or query the name:
49  
50 $var->Name ('USERS');
51 $text = $var->Name;
52  
53 =cut
54  
55 sub Name
56 1 ▶{
Subroutine Name: called CC=2 SCAR=7.1
Pod undocumented
57 1 my $self = shift;
58 1 ▶ $self->{name} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
59 1 return $self->{name};
60 }
61  
62 sub NameRef
63 0 ▶{
Subroutine NameRef: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my $self = shift;
65 0 return '$('. $self->Name .')';
66 }
67  
68 sub NameRefShell
69 0 ▶{
Subroutine NameRefShell: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my $self = shift;
71 0 return '$('. $self->Name .'_SHELL)';
72 }
73  
74 =pod
75  
76 $var->Values ('James Brine', 'George Loveless');
77 $var->Values ('Thomas Standfield');
78  
79 =cut
80  
81 sub Values
82 4 ▶{
Subroutine Values: called CC=1 SCAR=0.0
Pod undocumented
83 4 my $self = shift;
84 4 push @{$self->{value}}, @_;
85 4 return $self->{value};
86 }
87  
88 =pod
89  
90 Construct a text fragment that defines this variable suitable for use in a
91 Makefile like so:
92  
93 $text = $var->Assemble;
94  
95 =cut
96  
97 sub Assemble
98 8 ▶{
Subroutine Assemble: called CC=2 SCAR=6.9
Pod undocumented
99 8 my $self = shift;
100 8 ▶ return '' unless defined $self->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"name"} 0 8 8
101  
102 8 my $text;
103 8 $text .= quotetarget ($self->{name});
104 8 $text .= ' = ';
105 8 $text .= join ' ', (map { quotetarget ($_)} grep /./, @{$self->{value}});
106 8 $text .= "\n";
107 8 $text .= quotetarget ($self->{name} .'_SHELL');
108 8 $text .= ' = ';
109 8 my @items = map { quoteshell ($_)} grep /./, @{$self->{value}};
110 8 @items = map {s/\$\(([^)]+)\)/\$($1_SHELL)/g; $_} @items;
111 8 $text .= join ' ', @items;
112 8 $text .= "\n";
113 8 return $text;
114 }
115  
116 1 1;
« lib/Panotools/Matrix.pm ↑ Summary lib/Panotools/Script/Line/Mask.pm »