| 1 | package Lim::RPC::Value; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use common::sense; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Lim (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =encoding utf8 | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | ... | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | See L<Lim> for version. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =over 4 | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =item STRING | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =item INTEGER | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =item BOOL | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =item BASE64 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item OPT_REQUIRED | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =item OPT_NOTEMPTY | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =back | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 10 | our $VERSION = $Lim::VERSION; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub STRING (){ 'string' } | ||||||||||||||||||||||||||||
| 39 | sub INTEGER (){ 'integer' } | ||||||||||||||||||||||||||||
| 40 | sub BOOL (){ 'bool' } | ||||||||||||||||||||||||||||
| 41 | sub BASE64 (){ 'base64' } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 10 | our %TYPE = ( | |||||||||||||||||||||||||||
| 44 | STRING() => STRING, | ||||||||||||||||||||||||||||
| 45 | INTEGER() => INTEGER, | ||||||||||||||||||||||||||||
| 46 | BOOL() => BOOL, | ||||||||||||||||||||||||||||
| 47 | BASE64() => BASE64 | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | 10 | our %XSD_TYPE = ( | |||||||||||||||||||||||||||
| 50 | STRING() => 'xsd:string', | ||||||||||||||||||||||||||||
| 51 | INTEGER() => 'xsd:integer', | ||||||||||||||||||||||||||||
| 52 | BOOL() => 'xsd:boolean', | ||||||||||||||||||||||||||||
| 53 | BASE64() => 'xsd:base64Binary' | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | 10 | our %XMLRPC_TYPE = ( | |||||||||||||||||||||||||||
| 56 | STRING() => 'string', | ||||||||||||||||||||||||||||
| 57 | INTEGER() => 'int', | ||||||||||||||||||||||||||||
| 58 | BOOL() => 'boolean', | ||||||||||||||||||||||||||||
| 59 | BASE64() => 'base64' | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub OPT_REQUIRED (){ 0x00000001 } | ||||||||||||||||||||||||||||
| 63 | sub OPT_NOTEMPTY (){ 0x00000002 } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 10 | our %OPTIONS = ( | |||||||||||||||||||||||||||
| 66 | 'required' => OPT_REQUIRED, | ||||||||||||||||||||||||||||
| 67 | 'notEmpty' => OPT_NOTEMPTY | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 10 | our %NEGATIVE_OPTIONS = ( | |||||||||||||||||||||||||||
| 71 | 'optional' => OPT_REQUIRED, | ||||||||||||||||||||||||||||
| 72 | 'empty' => OPT_NOTEMPTY | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | ... | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head2 new | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 72 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=45.5
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 72 | my $this = shift; | |||||||||||||||||||||||||||
| 87 | 72 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||
| 88 | 72 | ▶ | my %args = scalar @_ > 1 ? ( @_ ) : ( textual => $_[0] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 72 | my $self = { | |||||||||||||||||||||||||||
| 90 | options => OPT_REQUIRED | OPT_NOTEMPTY | ||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 72 | ▶ | if (exists $args{textual}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 72 | foreach (split(/\s+/o, lc($args{textual}))) { | |||||||||||||||||||||||||||
| 95 | 80 | ▶ | if (exists $TYPE{$_}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 96 | 72 | ▶ | if (exists $self->{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | confess __PACKAGE__, ': type already defined'; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 72 | $self->{type} = $_; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | elsif (exists $OPTIONS{$_}) { | ||||||||||||||||||||||||||||
| 102 | 0 | $self->{options} |= $OPTIONS{$_}; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | elsif (exists $NEGATIVE_OPTIONS{$_}) { | ||||||||||||||||||||||||||||
| 105 | 8 | $self->{options} &= ~$NEGATIVE_OPTIONS{$_}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||
| 108 | 0 | confess __PACKAGE__, ': unknown RPC value setting "'.$_.'"'; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | unless (defined $args{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | confess __PACKAGE__, ': No type specified'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless (exists $TYPE{$args{type}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | confess __PACKAGE__, ': Invalid type specified'; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | $self->{type} = $args{type}; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (defined $args{options}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | unless (ref($args{options}) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | confess __PACKAGE__, ': Invalid options specified'; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | foreach (@{$args{options}}) { | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | if (exists $OPTIONS{$_}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 129 | 0 | $self->{options} |= $OPTIONS{$_}; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | elsif (exists $NEGATIVE_OPTIONS{$_}) { | ||||||||||||||||||||||||||||
| 132 | 0 | $self->{options} &= ~$NEGATIVE_OPTIONS{$_}; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||
| 135 | 0 | confess __PACKAGE__, ': Unknown RPC value option "'.$_.'"'; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 72 | ▶ | unless (exists $self->{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | confess __PACKAGE__, ': no type defined'; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 72 | bless $self, $class; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 72 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 149 | 72 | my ($self) = @_; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head2 type | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =cut | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub type { | ||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | $_[0]->{type}; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =head2 xsd_type | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub xsd_type { | ||||||||||||||||||||||||||
|
Subroutine
xsd_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 0 | $XSD_TYPE{$_[0]->{type}}; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head2 xmlrpc_type | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub xmlrpc_type { | ||||||||||||||||||||||||||
|
Subroutine
xmlrpc_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 0 | $XMLRPC_TYPE{$_[0]->{type}}; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head2 required | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 4 | ▶ | sub required { | ||||||||||||||||||||||||||
|
Subroutine
required: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 4 | ▶ | $_[0]->{options} & OPT_REQUIRED ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 comform | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =cut | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 4 | ▶ | sub comform { | ||||||||||||||||||||||||||
|
Subroutine
comform: called CC=4 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 4 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # TODO validate type | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 4 | ▶ | if (($self->{options} & OPT_NOTEMPTY)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 4 | ▶ | if (!defined $value or $value !~ /$\s*^/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and $value =~ /$\s*^/ou
MC/DC0%0/2
defined $value and $value =~ /$\s*^/ou
defined $value
$value =~ /$\s*^/ou
Truth table33%1/3
A and B
A= defined $valueB= $value =~ /$\s*^/ou
| |||||||||||||||||||||||||||||
| 195 | 0 | return 0; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 4 | return 1; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >> | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 BUGS | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Please report any bugs or feature requests to L<https://github.com/jelu/lim/issues>. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | perldoc Lim | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | You can also look for information at: | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =over 4 | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =item * Lim issue tracker (report bugs here) | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | L<https://github.com/jelu/lim/issues> | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =back | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | Copyright 2012-2013 Jerry Lundström. | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 233 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 234 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 10 | 1; # End of Lim::RPC::Value | |||||||||||||||||||||||||||