web/cgi-bin/yatt.lib/YATT/ArgTypes.pm

filter: Statementstmt 93.9% 77 / 82 Branchbran 73.3% 22 / 30 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 5 totaltotal 83.9% 115 / 137 CC 21 SCAR 19.5
CC
21
Cov
88%
add_type
14.9
parse_args
5.0
option_alias
3.0
CRAP 7.0
« blib/lib/YATT/Toplevel/FCGI.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/XHF.pm »
1 # -*- mode: perl; coding: utf-8 -*-
2 3 ▶package YATT::ArgTypes; use YATT::Inc;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base qw(YATT::Class::Configurable);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use YATT::Fields qw(cf_callpack
Subroutine BEGIN: called CC=1 SCAR=0.0
8 cf_base cf_type_map cf_type_fmt
9 cf_type_name
10 cf_debug
11 3 );
12 3 ▶use YATT::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use YATT::Util::Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
17 3 my $pack = shift;
18 3 my ($callpack) = caller;
19 3 my @types;
20 3 my $opts = $pack->new(callpack => $callpack
21 , $pack->parse_args(\@_, \@types));
22 3 $opts->add_type($_) for @types;
23 }
24  
25 3 ▶sub parse_args {
Subroutine parse_args: called CC=5 SCAR=16.2
Pod undocumented
26 3 my ($pack, $arglist, $taskqueue) = @_;
27 3 my @confs;
28 3 ▶ while (@$arglist) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$arglist) 33 3 36
29 33 ▶ if (ref $arglist->[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arglist->[0]) { } 21 12 33
elsif (() = $arglist->[0] =~ /^([\-:])(\w+)/) { } 12 0 12
30 21 push @$taskqueue, shift @$arglist;
31 } elsif (my ($flag, $key) = $arglist->[0] =~ /^([\-:])(\w+)/) {
32 12 shift @$arglist;
33 12 ▶ my $value = $flag eq ':' ? 1 : shift @$arglist;
Branch: 1 branch
BranchTrueFalseTotal
$flag eq ':' ? : 3 9 12
34 12 push @confs, $key, $value;
35 } else {
36 0 croak "Invalid option '$arglist->[0]'";
37 }
38 }
39 3 @confs;
40 }
41  
42 21 ▶sub add_type {
Subroutine add_type: called CC=13 SCAR=27.0
Pod undocumented
43 21 (my MY $self, my ($desc)) = @_;
44 21 my $type = shift @$desc;
45 21 my $fullclass = sprintf $self->{cf_type_fmt}, $type;
46  
47 21 $self->{cf_type_map}{$type} = $fullclass;
48  
49 define_const(globref($fullclass, "type_name"), $type)
50 21 ▶ if $self->{cf_type_name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cf_type_name"} 21 0 21
51  
52 # t_zzz typealias.
53 21 define_const(globref($self->{cf_callpack}, "t_$type"), $fullclass);
54  
55 21 my $fields = fields_hash($self);
56  
57 21 my (@symbols, @tasks, %config);
58 21 ▶ while (@$desc) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$desc) 27 21 48
59 27 ▶ if (ref $desc->[0] eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $desc->[0] eq 'SCALAR') { } 9 18 27
elsif (() = $desc->[0] =~ /^([\-:])(\w+)/) { } 18 0 18
60 9 my ($nameref, $value) = splice @$desc, 0, 2;
61 9 my $code = do {
62 9 ▶ unless (ref $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 0 9 9
if (do { ref $value eq 'CODE' }) { } 0 0 0
63 0 ▶ sub () { $value };
Subroutine __ANON__: not called CC=1 SCAR=1.2
64 } elsif (ref $value eq 'CODE') {
65 0 $value;
66 } else {
67 0 die "Unknown ArgType desc for $$nameref : '$value'";
68 }
69 };
70 9 push @symbols, [$$nameref, $code];
71 # *{globref($fullclass, $$nameref)} = $code;
72 } elsif (my ($flag, $key) = $desc->[0] =~ /^([\-:])(\w+)/) {
73 18 shift @$desc;
74 18 ▶ my $value = $flag eq ':' ? 1 : shift @$desc;
Branch: 1 branch
BranchTrueFalseTotal
$flag eq ':' ? : 0 18 18
75 18 ▶ if ($fields->{"cf_$key"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$fields{"cf_$key"}) { } 3 15 18
76 3 $config{"cf_$key"} = $value;
77 } else {
78 15 ▶ my $sub = $self->can("option_$key")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("option_$key") or die "Unknown ArgType option $key" 15 0 15
79 or die "Unknown ArgType option $key";
80 15 push @tasks, [$sub, $value];
81 }
82 # $sub->($self, $fullclass, $value);
83 } else {
84 0 die "Unknown desc type $desc"
85 }
86 }
87  
88 # base だけは eval を使う。 さもないと %FIELDS が作られない。
89 # *{globref($fullclass, 'ISA')} = [$self->{cf_base}];
90 $self->checked_eval
91 (sprintf qq{package %s; use base qw(%s)}
92 , $fullclass
93 , $self->lookup_in($self->{cf_type_map}, $config{cf_base})
94 21 ▶ || $$self{cf_base});
Condition66%2/3
$self->lookup_in($self->{'cf_type_map'}, $config{'cf_base'}) || $self->{'cf_base'}
l!l&&r!l&&!r
3180
MC/DC0%0/2
$self->lookup_in($self->{'cf_type_map'}, $config{'cf_base'}) || $self->{'cf_base'}
$self->lookup_in($self->{'cf_type_map'}, $config{'cf_base'}) $self->{'cf_base'}
Truth table66%2/3
A || B
A= $self->lookup_in($self->{'cf_type_map'}, $config{'cf_base'})B= $self->{'cf_base'}
ABresult
1X1
011
000
95  
96 21 foreach my $rec (@symbols) {
97 9 my ($sym, $code) = @$rec;
98 9 *{globref($fullclass, $sym)} = $code;
99 }
100  
101 21 foreach my $rec (@tasks) {
102 15 my ($sub, $value) = @$rec;
103 15 $sub->($self, $fullclass, $value, \%config);
104 }
105 }
106  
107 21 ▶sub lookup_in {
Subroutine lookup_in: called CC=2 SCAR=6.9
Pod undocumented
108 21 my ($self, $hash, $key) = @_;
109 21 ▶ return unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 18 3 21
110 3 $hash->{$key};
111 }
112  
113 9 ▶sub option_alias {
Subroutine option_alias: called CC=3 SCAR=11.0
Pod undocumented
114 9 (my MY $self, my ($class, $value)) = @_;
115 9 ▶ foreach my $alias (ref $value ? @$value : $value) {
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 3 6 9
116 12 $self->{cf_type_map}{$alias} = $class;
117 }
118 }
119  
120 6 ▶sub option_fields {
Subroutine option_fields: called CC=1 SCAR=0.0
Pod undocumented
121 6 (my MY $self, my ($class, $value)) = @_;
122 6 my $fields = terse_dump(@$value);
123 6 $self->checked_eval(<<END);
124 package $class; use YATT::Fields $fields;
125 END
126 }
127  
128 3 1;
« blib/lib/YATT/Toplevel/FCGI.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/XHF.pm »