Backend/OpenSsh/Role/MatchBlock.pm

filter: Statementstmt 98.5% 68 / 69 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 4 totaltotal 90.2% 93 / 103 CC 11 SCAR 10.2
CC
11
Cov
95%
write_match_block
5.1
write_match_condition
4.0
write_all_match_block
3.0
CRAP 2.8
« Backend/OpenSsh/Ssh.pm ↑ Summary OpenSsh.pm »
1 #
2 # This file is part of Config-Model-OpenSsh
3 #
4 # This software is Copyright (c) 2008-2025 by Dominique Dumont.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package Config::Model::Backend::OpenSsh::Role::MatchBlock ;
14 4 $Config::Model::Backend::OpenSsh::Role::MatchBlock::VERSION = '2.10.2.1';
15 4 ▶use Mouse::Role ;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 requires qw(current_node write_node_content write_line);
18  
19 4 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use IO::File ;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use File::Copy ;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use File::Path ;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 4 my $logger = Log::Log4perl::get_logger("Backend::OpenSsh");
26  
27 8 ▶sub match {
Subroutine match: called CC=2 SCAR=6.9
Pod undocumented
28 8 my ($self, $root, $key, $pairs, $comment, $check) = @_ ;
29 8 $logger->debug("match: @$pairs # $comment");
30 8 my $list_obj = $root->fetch_element('Match');
31  
32 # create new match block
33 8 my $nb_of_elt = $list_obj->fetch_size;
34 8 my $block_obj = $list_obj->fetch_with_id($nb_of_elt) ;
35 8 $block_obj->annotation($comment) ;
36  
37 8 ▶ while (@$pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pairs) 15 8 23
38 15 my $criteria = shift @$pairs;
39 15 my $pattern = shift @$pairs;
40 15 $block_obj->load(
41 steps => qq!Condition $criteria="$pattern"!,
42 check => $check,
43 );
44 }
45  
46 8 $self->current_node( $block_obj->fetch_element('Settings') );
47 }
48  
49  
50 13 ▶sub write_all_match_block {
Subroutine write_all_match_block: called CC=3 SCAR=11.0
Pod undocumented
51 13 my $self = shift ;
52 13 my $match_elt = shift ;
53 13 ▶ my $mode = shift || '';
Condition100%2/2
shift() || ''
l!l
94
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
54  
55 13 my $result = '';
56 13 foreach my $elt ($match_elt->fetch_all($mode) ) {
57 4 $result .= $self->write_match_block($elt,$mode) ;
58 }
59  
60 13 return $result ;
61 }
62  
63 4 ▶sub write_match_block {
Subroutine write_match_block: called CC=5 SCAR=16.4
Pod undocumented
64 4 my $self = shift ;
65 4 my $match_elt = shift ;
66 4 ▶ my $mode = shift || '';
Condition50%1/2
shift() || ''
l!l
04
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
67  
68 4 my $match_line ;
69 my $match_body ;
70  
71 4 foreach my $name ($match_elt->get_element_name() ) {
72 8 my $elt = $match_elt->fetch_element($name) ;
73  
74 8 ▶ if ($name eq 'Settings') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'Settings') { } 4 4 8
elsif ($name eq 'Condition') { } 4 0 4
75 4 $match_body .= $self->write_node_content($elt,$mode)."\n" ;
76 }
77 elsif ($name eq 'Condition') {
78 4 $match_line = $self->write_line(
79 Match => $self->write_match_condition($elt,$mode) ,
80 $match_elt -> annotation
81 ) ;
82 }
83 else {
84 0 die "write_match_block: unexpected element: $name";
85 }
86 }
87  
88 4 return $match_line.$match_body ;
89 }
90  
91 4 ▶sub write_match_condition {
Subroutine write_match_condition: called CC=4 SCAR=13.9
Pod undocumented
92 4 my $self = shift ;
93 4 my $cond_elt = shift ;
94 4 ▶ my $mode = shift || '';
Condition50%1/2
shift() || ''
l!l
04
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
95  
96 4 my $result = '' ;
97  
98 4 foreach my $name ($cond_elt->get_element_name() ) {
99 16 my $elt = $cond_elt->fetch_element($name) ;
100 16 my $v = $elt->fetch($mode) ;
101 16 ▶ $result .= " $name $v" if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 8 8 16
102 }
103  
104 4 return $result ;
105 }
106  
107 4 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 4 1;
110  
111 # ABSTRACT: Backend role for Ssh Match blocks
112  
113 __END__
« Backend/OpenSsh/Ssh.pm ↑ Summary OpenSsh.pm »