lib/SDL2/Utils/Type/Enum.pm

filter: Statementstmt 35.5% 27 / 76 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 1 totaltotal 22.7% 35 / 154 CC 34 SCAR 63.5
CC
34
Cov
20%
ffi_custom_type_api_1
859.0
__ANON__
12.0
__ANON__
6.0
CRAP 574.2
« blib/lib/SDL2/Utils.pm ↑ Summary lib/SDL2/Utils.pm »
1 3 package SDL2::Utils::Type::Enum { # Cribbed from FFI::Platypus::Type::Enum
2 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶ use constant 1.32 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶ use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶ use Ref::Util qw( is_plain_arrayref is_plain_hashref is_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶ use Scalar::Util qw( dualvar );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶ use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Custom platypus type for dealing with C enumerated types
11 3 our $VERSION = '0.07'; # VERSION
12 3 our @CARP_NOT = qw( FFI::Platypus );
13  
14 sub ffi_custom_type_api_1 {
15 0 ▶ my %config = defined $_[2] && is_plain_hashref $_[2] ? %{ splice( @_, 2, 1 ) } : ();
Subroutine ffi_custom_type_api_1: not called CC=30 SCAR=67.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] && is_plain_hashref($_[2]) ? : 0 0 0
Condition0%0/3
defined $_[2] and is_plain_hashref($_[2])
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[2] and is_plain_hashref($_[2])
defined $_[2] is_plain_hashref($_[2])
Truth table0%0/3
A and B
A= defined $_[2]B= is_plain_hashref($_[2])
ABresult
0X0
100
111
16 0 my ( undef, undef, @values ) = @_;
17 0 my $index = 0;
18 0 my %str_lookup;
19 my %int_lookup;
20 0 ▶ my $prefix = defined $config{prefix} ? $config{prefix} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $config{'prefix'} ? : 0 0 0
21 0 ▶ $config{rev} ||= 'str';
Condition0%0/2
$config{"rev"} ||= "str"
l!l
00
MC/DC0%0/1
$config{"rev"} ||= "str"
$config{"rev"}
Truth table0%0/2
A
A= $config{"rev"}
Aresult
11
00
22 0 ▶ ( $config{rev} =~ /^(int|str|dualvar)$/ ) or
Branch: 1 branch
BranchTrueFalseTotal
$config{"rev"} =~ /^(int|str|dualvar)$/ or croak("rev must be either 'int', 'str', or 'dualvar'") 0 0 0
23 croak("rev must be either 'int', 'str', or 'dualvar'");
24 0 ▶ $config{casing} ||= 'upper';
Condition0%0/2
$config{"casing"} ||= "upper"
l!l
00
MC/DC0%0/1
$config{"casing"} ||= "upper"
$config{"casing"}
Truth table0%0/2
A
A= $config{"casing"}
Aresult
11
00
25 0 ▶ ( $config{casing} =~ /^(upper|keep)$/ ) or croak("casing must be either 'upper' or 'keep'");
Branch: 1 branch
BranchTrueFalseTotal
$config{"casing"} =~ /^(upper|keep)$/ or croak("casing must be either 'upper' or 'keep'") 0 0 0
26  
27 0 foreach my $value (@values) {
28 0 my $name;
29 my @aliases;
30 0 ▶ if ( is_plain_arrayref $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_plain_arrayref($value)) { } 0 0 0
elsif (not is_ref($value)) { } 0 0 0
31 0 my %opt;
32 0 ▶ if ( @$value % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$value % 2) { } 0 0 0
33 0 ( $name, %opt ) = @$value;
34 }
35 else {
36 0 ( $name, $index, %opt ) = @$value;
37 }
38 0 ▶ @aliases = @{ delete $opt{alias} || [] };
Branch: 1 branch
BranchTrueFalseTotal
delete $opt{"alias"} or [] 0 0 0
39 0 ▶ croak("unrecognized options: @{[ sort keys %opt ]}") if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 0 0
40 }
41 elsif ( !is_ref $value) {
42 0 $name = $value;
43 }
44 else {
45 0 croak("not a array ref or scalar: $value");
46 }
47 0 ▶ if ( $index < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0) 0 0 0
48 0 ▶ $config{type} ||= 'senum';
Condition0%0/2
$config{"type"} ||= "senum"
l!l
00
MC/DC0%0/1
$config{"type"} ||= "senum"
$config{"type"}
Truth table0%0/2
A
A= $config{"type"}
Aresult
11
00
49 }
50 0 ▶ if ( my $packages = $config{package} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packages = $config{"package"}) 0 0 0
51 0 ▶ foreach my $package ( is_plain_arrayref $packages ? @$packages : $packages ) {
Branch: 1 branch
BranchTrueFalseTotal
is_plain_arrayref($packages) ? : 0 0 0
52 0 foreach my $name ( $name, @aliases ) {
53 my $full = join '::', $package,
54 0 ▶ $prefix . ( $config{casing} eq 'upper' ? uc($name) : $name );
Branch: 1 branch
BranchTrueFalseTotal
$config{'casing'} eq 'upper' ? : 0 0 0
55 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 0 ▶ ref $index eq 'CODE' ? *{$full} = $index :
Branch: 1 branch
BranchTrueFalseTotal
ref $index eq 'CODE' ? : 0 0 0
57 constant->import( $full, $index );
58 }
59 }
60 }
61 0 ▶ croak("$name declared twice") if exists $str_lookup{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $str_lookup{$name} 0 0 0
62 0 ▶ $int_lookup{$index} = $name unless exists $int_lookup{$index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $int_lookup{$index} 0 0 0
63 0 $str_lookup{$_} = $index for @aliases;
64 0 $str_lookup{$name} = $index++;
65 }
66 0 ▶ $config{type} ||= 'enum';
Condition0%0/2
$config{"type"} ||= "enum"
l!l
00
MC/DC0%0/1
$config{"type"} ||= "enum"
$config{"type"}
Truth table0%0/2
A
A= $config{"type"}
Aresult
11
00
67 0 ▶ if ( defined $config{maps} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config{"maps"}) 0 0 0
68 0 ▶ if ( is_plain_arrayref $config{maps} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_plain_arrayref($config{'maps'})) { } 0 0 0
69 0 @{ $config{maps} } = ( \%str_lookup, \%int_lookup, $config{type} );
70 }
71 else {
72 0 croak("maps is not an array reference");
73 }
74 }
75 my %type = (
76 native_type => $config{type},
77 perl_to_native => sub {
78 exists $str_lookup{ $_[0] } ? $str_lookup{ $_[0] } :
79 0 ▶ exists $int_lookup{ $_[0] } ? $_[0] :
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
exists $str_lookup{$_[0]} ? : 0 0 0
exists $int_lookup{$_[0]} ? : 0 0 0
80 croak("illegal enum value $_[0]");
81 }
82 0 );
83 0 ▶ if ( $config{rev} eq 'str' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config{'rev'} eq 'str') { } 0 0 0
elsif ($config{'rev'} eq 'dualvar') { } 0 0 0
84 $type{native_to_perl} = sub {
85 0 ▶ exists $int_lookup{ $_[0] } ? $int_lookup{ $_[0] } : $_[0];
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
exists $int_lookup{$_[0]} ? : 0 0 0
86 }
87 0 }
88 elsif ( $config{rev} eq 'dualvar' ) {
89 $type{native_to_perl} = sub {
90 0 ▶ exists $int_lookup{ $_[0] } ? dualvar( $_[0], $int_lookup{ $_[0] } ) : $_[0];
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
exists $int_lookup{$_[0]} ? : 0 0 0
91 0 };
92 }
93 0 \%type;
94 }
95 3 1;
96 }
« blib/lib/SDL2/Utils.pm ↑ Summary lib/SDL2/Utils.pm »