| 1 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # MKDoc::Control_List | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Author: Jean-Michel Hiver | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Description: Access Control List generalization | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package MKDoc::Control_List; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.31'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | return bless { @_ }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub process | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | $self->{'caller'} = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my $code = $self->_compile(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | my @res = $code->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | return @res; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _read_data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_data: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return $self->{data} || $self->_read_file(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'data'} || $self->_read_file
MC/DC0%0/2
$self->{'data'} || $self->_read_file
$self->{'data'}
$self->_read_file
Truth table66%2/3
A || B
A= $self->{'data'}B= $self->_read_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sub _read_file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_file: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $file = $self->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | open FP, "<:utf8", $file || die "Cannot read-open $file. Reason: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file || die("Cannot read-open $file. Reason: $@")
MC/DC0%0/1
$file || die("Cannot read-open $file. Reason: $@")
$file
Truth table50%1/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $data = join '', <FP>; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | close FP; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub _compile | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | $self->{_code} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_code"} ||= do {
my $code = $self->_build_code;
my $VAR1 = undef;
eval $code;
$@ and die $@;
$VAR1
}
MC/DC0%0/2
$self->{"_code"} ||= do {
my $code = $self->_build_code;
my $VAR1 = undef;
eval $code;
$@ and die $@;
$VAR1
}
$self->{"_code"}
do {
my $code = $self->_build_code;
my $VAR1 = undef;
eval $code;
$@ and die $@;
$VAR1
}
Truth table66%2/3
A ||= B
A= $self->{"_code"}B= do {
my $code = $self->_build_code;
my $VAR1 = undef;
eval $code;
$@ and die $@;
$VAR1
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $code = $self->_build_code(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $VAR1 = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | eval $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | $@ && die $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | $VAR1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | return $self->{_code}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub _build_code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $data = $self->_read_data(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | my @res = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | push @res, $self->_build_code_header(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | foreach my $line (split /\n/, $data) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 22 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 22 | chomp ($line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 22 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 22 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 22 | ▶ | $line =~ /^#/ && next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 22 | ▶ | $line || next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | push @res, $self->_build_code_condition ($line) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | $self->_build_code_ret_value ($line) || | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 18 | ▶ | $self->_build_code_rule ($line) || do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
$self->_build_code_condition($line) || $self->_build_code_ret_value($line) || $self->_build_code_rule($line) || do {
warn "Cannot parse line $count.\n$line";
next
}
$self->_build_code_condition($line) or $self->_build_code_ret_value($line) or $self->_build_code_rule($line)
$self->_build_code_condition($line) or $self->_build_code_ret_value($line)
MC/DC0%0/4
$self->_build_code_condition($line) || $self->_build_code_ret_value($line) || $self->_build_code_rule($line) || do {
warn "Cannot parse line $count.\n$line";
next
}
$self->_build_code_condition($line)
$self->_build_code_ret_value($line)
$self->_build_code_rule($line)
do {
warn "Cannot parse line $count.\n$line";
next
}
Truth table60%3/5
A or B or C || D
A= $self->_build_code_condition($line)B= $self->_build_code_ret_value($line)C= $self->_build_code_rule($line)D= do {
warn "Cannot parse line $count.\n$line";
next
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | warn "Cannot parse line $count.\n$line"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | push @res, $self->_build_code_footer(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | return join "\n", @res; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub _build_code_header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | my $caller = $self->{'caller'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | "\$VAR1 = sub { package $caller;", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | sub _build_code_condition | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code_condition: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 21 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 21 | ▶ | $line =~ /^\s*CONDITION\s+/ || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | $line =~ s/^\s*CONDITION\s+(\w+)\s+(.*)$/my \$cnd_$1 = do { $2 };/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub _build_code_ret_value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code_ret_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | ▶ | $line =~ /^\s*RET_VALUE\s+/ || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | $line =~ s/^\s*RET_VALUE\s+(\w+)\s+(.*)$/my \$ret_$1 = do { $2 };/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | sub _build_code_rule | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code_rule: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | ▶ | $line =~ /^\s*RULE\s+.+?\s+WHEN\s+.+\s*/ || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | my ($ret_values, $conditions) = $line =~ /^\s*RULE\s+(.+?)\s+WHEN\s+(.+?)\s*$/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 9 | my @ret_values = $ret_values =~ /(\w+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | my @conditions = $conditions =~ /(\w+)/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my $code = join ' && ', map { "\$cnd_$_" } @conditions; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | $code .= ' && return ( ' . join ', ', map { "\$ret_$_" } @ret_values; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | $code .= ' );'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | sub _build_code_footer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_code_footer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | return ( 'return;', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | '};' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||