blib/lib/FFI/Platypus/TypeParser.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 9 totaltotal 88.8% 72 / 81 CC 5 SCAR 4.4
CC
5
Cov
100%
create_type_custom
3.0
type_map
2.0
abi
2.0
CRAP 1.6
« blib/lib/FFI/Platypus/Buffer.pm ↑ Summary blib/lib/FFI/Platypus/Closure.pm »
1 package FFI::Platypus::TypeParser;
2  
3 52 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 52 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 52 ▶use List::Util 1.45 qw( uniqstr );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 52 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: FFI Type Parser
10 52 our $VERSION = '2.11'; # VERSION
11  
12  
13 # The TypeParser and Type classes are used internally ONLY and
14 # are not to be exposed to the user. External users should
15 # not under any circumstances rely on the implementation of
16 # these classes.
17  
18 sub new
19 {
20 423 ▶ my($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
21 423 my $self = bless { types => {}, type_map => {}, abi => -1 }, $class;
22 423 $self->build;
23 423 $self;
24 }
25  
26 ▶sub build {}
Subroutine build: called CC=1 SCAR=0.0
Pod undocumented
27  
28 52 our %basic_type;
29  
30 # this just checks if the underlying libffi/platypus implementation
31 # has the basic type. It is used mainly to verify that exotic types
32 # like longdouble and complex_float are available before the test
33 # suite tries to use them.
34 sub have_type
35 {
36 24371 ▶ my(undef, $name) = @_;
Subroutine have_type: called CC=1 SCAR=0.0
Pod undocumented
37 24371 !!$basic_type{$name};
38 }
39  
40 sub create_type_custom
41 {
42 207 ▶ my($self, $name, @rest) = @_;
Subroutine create_type_custom: called CC=3 SCAR=11.0
Pod undocumented
43 207 ▶ $name = 'opaque' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 6 201 207
44 207 my $type = $self->parse($name);
45 207 ▶ unless($type->is_customizable)
Branch: 1 branch
BranchTrueFalseTotal
unless ($type->is_customizable) 2 205 207
46 {
47 2 croak "$name is not a legal basis for a custom type"
48 }
49 205 $self->_create_type_custom($type, @rest);
50 }
51  
52 # this is the type map provided by the language plugin, if any
53 # in addition to the basic types (which map to themselves).
54 sub type_map
55 {
56 3463 ▶ my($self, $new) = @_;
Subroutine type_map: called CC=2 SCAR=6.9
Pod undocumented
57  
58 3463 ▶ if(defined $new)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 356 3107 3463
59 {
60 356 $self->{type_map} = $new;
61 }
62  
63 3463 $self->{type_map};
64 }
65  
66 # this stores the types that have been mentioned so far. It also
67 # usually includes aliases.
68 sub types
69 {
70 7723 ▶ shift->{types};
Subroutine types: called CC=1 SCAR=0.0
Pod undocumented
71 }
72  
73 # The type parser needs to know the ABI when creating closures
74 sub abi
75 {
76 116 ▶ my($self, $new) = @_;
Subroutine abi: called CC=2 SCAR=6.9
Pod undocumented
77 116 ▶ $self->{abi} = $new if defined $new;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new 11 105 116
78 116 $self->{abi};
79 }
80  
81 {
82 52 my %store;
83  
84 52 foreach my $name (keys %basic_type)
85 {
86 832 my $type_code = $basic_type{$name};
87 832 $store{basic}->{$name} = __PACKAGE__->create_type_basic($type_code);
88 832 $store{ptr}->{$name} = __PACKAGE__->create_type_pointer($type_code);
89 832 $store{rev}->{$type_code} = $name;
90 }
91  
92 sub global_types
93 {
94 4786 ▶ \%store;
Subroutine global_types: called CC=1 SCAR=0.0
Pod undocumented
95 }
96 }
97  
98 # list all the types that this type parser knows about, including
99 # those provided by the language plugin (if any), those defined
100 # by the user, and the basic types that everyone gets.
101 sub list_types
102 52 {
103 3 ▶ my($self) = @_;
Subroutine list_types: called CC=1 SCAR=0.0
Pod undocumented
104 3 uniqstr( ( keys %{ $self->type_map } ), ( keys %{ $self->types } ) );
105 }
106  
107 52 our @CARP_NOT = qw( FFI::Platypus );
108  
109 52 1;
110  
111 __END__
« blib/lib/FFI/Platypus/Buffer.pm ↑ Summary blib/lib/FFI/Platypus/Closure.pm »