lib/Module/Build/Notes.pm

filter: Statementstmt 100% 98 / 98 Branchbran 81.5% 31 / 38 Conditioncond 65.0% 13 / 20 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 14 / 14 Podpod 12.5% 1 / 8 totaltotal 85.3% 163 / 191 CC 29 SCAR 17.5
CC
29
Cov
91%
write
12.0
_same
5.6
read
5.0
CRAP 5.8
« lib/Module/Build/PodParser.pm ↑ Summary blib/lib/Module/Build/Platform/cygwin.pm »
1 package Module::Build::Notes;
2  
3 # A class for persistent hashes
4  
5 297 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 297 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 297 our $VERSION = '0.4234';
8 297 $VERSION = eval $VERSION;
9 297 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 297 ▶use Module::Build::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3378 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
13 3378 my ($class, %args) = @_;
14 3378 ▶ my $file = delete $args{file} or die "Missing required parameter 'file' to new()";
Branch: 1 branch
BranchTrueFalseTotal
my $file = delete $args{"file"} or die "Missing required parameter 'file' to new()" 3378 0 3378
15 3378 my $self = bless {
16 disk => {},
17 new => {},
18 file => $file,
19 %args,
20 }, $class;
21 }
22  
23 2880 ▶sub restore {
Subroutine restore: called CC=3 SCAR=11.1
Pod undocumented
24 2880 my $self = shift;
25  
26 2880 ▶ open(my $fh, '<', $self->{file}) or die "Can't read $self->{file}: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $self->{"file"} or die qq[Can't read $self->{"file"}: $!] 2880 0 2880
27 2880 $self->{disk} = eval do {local $/; <$fh>};
28 2880 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2880 2880
29 2880 close $fh;
30 2880 $self->{new} = {};
31 }
32  
33 133 ▶sub access {
Subroutine access: called CC=3 SCAR=11.0
Pod undocumented
34 133 my $self = shift;
35 133 ▶ return $self->read() unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 83 50 133
36  
37 50 my $key = shift;
38 50 ▶ return $self->read($key) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 19 31 50
39  
40 31 my $value = shift;
41 31 $self->write({ $key => $value });
42 31 return $self->read($key);
43 }
44  
45 186 ▶sub has_data {
Subroutine has_data: called CC=1 SCAR=0.0
Pod undocumented
46 186 my $self = shift;
47 186 return keys %{$self->read()} > 0;
48 }
49  
50 2 ▶sub exists {
Subroutine exists: called CC=2 SCAR=8.1
Pod undocumented
51 2 my ($self, $key) = @_;
52 2 ▶ return exists($self->{new}{$key}) || exists($self->{disk}{$key});
Condition33%1/3
exists $self->{'new'}{$key} || exists $self->{'disk'}{$key}
l!l&&r!l&&!r
002
MC/DC0%0/2
exists $self->{'new'}{$key} || exists $self->{'disk'}{$key}
exists $self->{'new'}{$key} exists $self->{'disk'}{$key}
Truth table33%1/3
A || B
A= exists $self->{'new'}{$key}B= exists $self->{'disk'}{$key}
ABresult
1X1
011
000
53 }
54  
55 482 ▶sub read {
Subroutine read: called CC=5 SCAR=16.1
Pod undocumented
56 482 my $self = shift;
57  
58 482 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 50 432 482
59 # Return 1 key as a scalar
60 50 my $key = shift;
61 50 ▶ return $self->{new}{$key} if exists $self->{new}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"new"}{$key} 2 48 50
62 48 return $self->{disk}{$key};
63 }
64  
65 # Return all data
66 432 my $out = (keys %{$self->{new}}
67 7 ? {%{$self->{disk}}, %{$self->{new}}}
68 432 ▶ : $self->{disk});
Branch: 1 branch
BranchTrueFalseTotal
keys %{$$self{'new'};} ? : 7 425 432
69 432 ▶ return wantarray ? %$out : $out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 428 432
70 }
71  
72 96 ▶sub _same {
Subroutine _same: called CC=5 SCAR=17.2
73 96 my ($self, $x, $y) = @_;
74 96 ▶ return 1 if !defined($x) and !defined($y);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x or defined $y 0 96 96
Condition33%1/3
defined $x or defined $y
l!l&&r!l&&!r
9600
MC/DC0%0/2
defined $x or defined $y
defined $x defined $y
Truth table33%1/3
A or B
A= defined $xB= defined $y
ABresult
1X1
011
000
75 96 ▶ return 0 if !defined($x) or !defined($y);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x and defined $y 2 94 96
Condition66%2/3
defined $x and defined $y
!ll&&!rl&&r
0294
MC/DC50%1/2
defined $x and defined $y
defined $x defined $y
Truth table66%2/3
A and B
A= defined $xB= defined $y
ABresult
0X0
100
111
76 94 return $x eq $y;
77 }
78  
79 259 ▶sub write {
Subroutine write: called CC=12 SCAR=24.9
Pod documented
80 259 my ($self, $href) = @_;
81 259 ▶ $href ||= {};
Condition100%2/2
$href ||= {}
l!l
22336
MC/DC100%1/1
$href ||= {}
$href
Truth table100%2/2
A
A= $href
Aresult
11
00
82  
83 259 @{$self->{new}}{ keys %$href } = values %$href; # Merge
84  
85 # Do some optimization to avoid unnecessary writes
86 259 foreach my $key (keys %{ $self->{new} }) {
87 240 ▶ next if ref $self->{new}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"new"}{$key} 9 231 240
88 231 ▶ next if ref $self->{disk}{$key} or !exists $self->{disk}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"disk"}{$key} or not exists $self->{"disk"}{$key} 135 96 231
Condition66%2/3
ref $self->{"disk"}{$key} or not exists $self->{"disk"}{$key}
l!l&&r!l&&!r
013596
MC/DC50%1/2
ref $self->{"disk"}{$key} or not exists $self->{"disk"}{$key}
ref $self->{"disk"}{$key} not exists $self->{"disk"}{$key}
Truth table66%2/3
A or not(B)
A= ref $self->{"disk"}{$key}B= not exists $self->{"disk"}{$key}
ABresult
1X1
011
000
89 96 ▶ delete $self->{new}{$key} if $self->_same($self->{new}{$key}, $self->{disk}{$key});
Branch: 1 branch
BranchTrueFalseTotal
if $self->_same($self->{"new"}{$key}, $self->{"disk"}{$key}) 88 8 96
90 }
91  
92 259 ▶ if (my $file = $self->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->{"file"}) 259 0 259
93 259 my ($vol, $dir, $base) = File::Spec->splitpath($file);
94 259 $dir = File::Spec->catpath($vol, $dir, '');
95 259 ▶ return unless -e $dir && -d $dir; # The user needs to arrange for this
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir and -d $dir 28 231 259
Condition66%2/3
-e $dir and -d $dir
!ll&&!rl&&r
280231
MC/DC50%1/2
-e $dir and -d $dir
-e $dir -d $dir
Truth table66%2/3
A and B
A= -e $dirB= -d $dir
ABresult
0X0
100
111
96  
97 231 ▶ return if -e $file and !keys %{ $self->{new} }; # Nothing to do
Branch: 1 branch
BranchTrueFalseTotal
if -e $file and not keys %{$$self{"new"};} 123 108 231
Condition100%3/3
-e $file and not keys %{$$self{"new"};}
!ll&&!rl&&r
3105123
MC/DC100%2/2
-e $file and not keys %{$$self{"new"};}
-e $file not keys %{$$self{"new"};}
Truth table100%3/3
A and not(B)
A= -e $fileB= not keys %{$$self{"new"};}
ABresult
0X0
100
111
98  
99 108 @{$self->{disk}}{ keys %{$self->{new}} } = values %{$self->{new}}; # Merge
100 108 $self->_dump($file, $self->{disk});
101  
102 108 $self->{new} = {};
103 }
104 108 return $self->read;
105 }
106  
107 108 ▶sub _dump {
Subroutine _dump: called CC=2 SCAR=7.0
108 108 my ($self, $file, $data) = @_;
109  
110 108 ▶ open(my $fh, '>', $file) or die "Can't create '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "Can't create '${file}': $!" 108 0 108
111 108 print {$fh} Module::Build::Dumper->_data_dump($data);
112 108 close $fh;
113 }
114  
115 297 my $orig_template = do { local $/; <DATA> };
116 297 close DATA;
117  
118 1 ▶sub write_config_data {
Subroutine write_config_data: called CC=3 SCAR=11.0
Pod undocumented
119 1 my ($self, %args) = @_;
120  
121 1 my $template = $orig_template;
122 1 $template =~ s/NOTES_NAME/$args{config_module}/g;
123 1 $template =~ s/MODULE_NAME/$args{module}/g;
124 1 $template =~ s/=begin private\n//;
125 1 $template =~ s/=end private/=cut/;
126  
127 # strip out private POD markers we use to keep pod from being
128 # recognized for *this* source file
129 1 $template =~ s{$_\n}{} for '=begin private', '=end private';
130  
131 1 ▶ open(my $fh, '>', $args{file}) or die "Can't create '$args{file}': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $args{"file"} or die qq[Can't create '$args{"file"}': $!] 1 0 1
132 1 print {$fh} $template;
133 1 print {$fh} "\n__DATA__\n";
134 1 print {$fh} Module::Build::Dumper->_data_dump([$args{config_data}, $args{feature}, $args{auto_features}]);
135 1 close $fh;
136 }
137  
138 297 1;
139  
140  
141 =head1 NAME
142  
143 Module::Build::Notes - Create persistent distribution configuration modules
144  
145 =head1 DESCRIPTION
146  
147 This module is used internally by Module::Build to create persistent
148 configuration files that can be installed with a distribution. See
149 L<Module::Build::ConfigData> for an example.
150  
151 =head1 AUTHOR
152  
153 Ken Williams <kwilliams@cpan.org>
154  
155 =head1 COPYRIGHT
156  
157 Copyright (c) 2001-2006 Ken Williams. All rights reserved.
158  
159 This library is free software; you can redistribute it and/or
160 modify it under the same terms as Perl itself.
161  
162 =head1 SEE ALSO
163  
164 perl(1), L<Module::Build>(3)
165  
166 =cut
167  
168 __DATA__
« lib/Module/Build/PodParser.pm ↑ Summary blib/lib/Module/Build/Platform/cygwin.pm »