OpenPGP/Config.pm

filter: Statementstmt 100% 70 / 70 Branchbran 71.4% 10 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 4 totaltotal 87.1% 102 / 117 CC 10 SCAR 12.0
CC
10
Cov
92%
read_config
8.4
_set_bool
3.0
BEGIN
1.0
CRAP 3.3
« OpenPGP/S2k.pm ↑ Summary OpenPGP/Armour.pm »
1 package Crypt::OpenPGP::Config;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 our $VERSION = '1.21'; # VERSION
6  
7 11 ▶use parent qw( Crypt::OpenPGP::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 12 my $class = shift;
11 12 my $cfg = bless { o => { @_ } }, $class;
12 12 $cfg;
13 }
14  
15 66 ▶sub get { $_[0]->{o}{ $_[1] } }
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
16 4 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
17 4 my $cfg = shift;
18 4 my($key, $val) = @_;
19 4 $cfg->{o}{$key} = $val;
20 }
21  
22 {
23 11 my %STANDARD = (
24 str => \&_set_str,
25 bool => \&_set_bool,
26 );
27  
28 4 ▶ sub read_config {
Subroutine read_config: called CC=8 SCAR=21.3
Pod undocumented
29 4 my $cfg = shift;
30 4 my($compat, $cfg_file) = @_;
31 4 my $class = join '::', __PACKAGE__, $compat;
32 4 my $directives = $class->directives;
33 4 local($_, $/);
34 4 $/ = "\n";
35 4 ▶ open ( my $fh, "<", $cfg_file ) or
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $cfg_file or return $cfg->error("Error opening file '${cfg_file}': $!") 4 0 4
36 return $cfg->error("Error opening file '$cfg_file': $!");
37 4 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 12 4 16
38 12 chomp;
39 12 ▶ next if !/\S/ || /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if not /\S/ or /^#/ 0 12 12
Condition33%1/3
not /\S/ or /^#/
l!l&&r!l&&!r
0012
MC/DC0%0/2
not /\S/ or /^#/
not /\S/ /^#/
Truth table33%1/3
not(A) or B
A= not /\S/B= /^#/
ABresult
1X1
011
000
40 12 ▶ if (/^\s*([^\s=]+)(?:(?:(?:\s*=\s*)|\s+)(.*))?/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*([^\s=]+)(?:(?:(?:\s*=\s*)|\s+)(.*))?/) 12 0 12
41 12 my($key, $val) = ($1, $2);
42 12 my $ref = $directives->{lc $key};
43 12 ▶ next unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 12 12
44 my $code = ref($ref->[0]) eq 'CODE' ? $ref->[0] :
45 12 ▶ $STANDARD{$ref->[0]};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref->[0] eq 'CODE' ? : 4 8 12
46 12 $code->($cfg, $ref->[1], $val);
47 }
48 }
49 4 close $fh;
50 }
51 }
52  
53 4 ▶sub _set_str { $_[0]->{o}{$_[1]} = $_[2] }
Subroutine _set_str: called CC=1 SCAR=0.0
54 {
55 11 my %BOOL = ( off => 0, on => 1 );
56 4 ▶ sub _set_bool {
Subroutine _set_bool: called CC=3 SCAR=11.0
57 4 my($cfg, $key, $val) = @_;
58 4 ▶ $val = 1 unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 2 2 4
59 4 ▶ $val = $BOOL{$val} || $val;
Condition66%2/3
$BOOL{$val} || $val
l!l&&r!l&&!r
220
MC/DC0%0/2
$BOOL{$val} || $val
$BOOL{$val} $val
Truth table66%2/3
A || B
A= $BOOL{$val}B= $val
ABresult
1X1
011
000
60 4 $cfg->{o}{$key} = $val;
61 }
62 }
63  
64 11 package Crypt::OpenPGP::Config::GnuPG;
65 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 2 ▶sub directives {
Subroutine directives: called CC=1 SCAR=0.0
68 {
69 2 armor => [ 'bool', 'Armour' ],
70 'default-key' => [ 'str', 'DefaultKey' ],
71 recipient => [ 'str', 'Recipient' ],
72 'default-recipient' => [ 'str', 'DefaultRecipient' ],
73 'default-recipient-self' => [ 'bool', 'DefaultSelfRecipient' ],
74 'encrypt-to' => [ 'str', 'Recipient' ],
75 verbose => [ 'bool', 'Verbose' ],
76 textmode => [ 'bool', 'TextMode' ],
77 keyring => [ 'str', 'PubRing' ],
78 'secret-keyring' => [ 'str', 'SecRing' ],
79 'cipher-algo' => [ \&_set_cipher ],
80 'digest-algo' => [ 'str', 'Digest' ],
81 'compress-algo' => [ \&_set_compress ],
82 }
83 }
84  
85 {
86 11 my %Ciphers = (
87 '3DES' => 'DES3', BLOWFISH => 'Blowfish',
88 RIJNDAEL => 'Rijndael', RIJNDAEL192 => 'Rijndael192',
89 RIJNDAEL256 => 'Rijndael256', TWOFISH => 'Twofish',
90 CAST5 => 'CAST5',
91 );
92 2 ▶ sub _set_cipher { $_[0]->{o}{Cipher} = $Ciphers{$_[2]} }
Subroutine _set_cipher: called CC=1 SCAR=0.0
93  
94 11 my %Compress = ( 1 => 'ZIP', 2 => 'Zlib' );
95 2 ▶ sub _set_compress { $_[0]->{o}{Compress} = $Compress{$_[2]} }
Subroutine _set_compress: called CC=1 SCAR=0.0
96 }
97  
98 11 package Crypt::OpenPGP::Config::PGP2;
99 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 2 ▶sub directives {
Subroutine directives: called CC=1 SCAR=0.0
102 {
103 2 armor => [ 'bool', 'Armour' ],
104 compress => [ 'bool', 'Compress' ],
105 encrypttoself => [ 'bool', 'EncryptToSelf' ],
106 myname => [ 'str', 'DefaultSelfRecipient' ],
107 pubring => [ 'str', 'PubRing' ],
108 secring => [ 'str', 'SecRing' ],
109 }
110 }
111  
112 package Crypt::OpenPGP::Config::PGP5;
113 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 11 *directives = \&Crypt::OpenPGP::Config::PGP2::directives;
116  
117 11 1;
« OpenPGP/S2k.pm ↑ Summary OpenPGP/Armour.pm »