blib/lib/UUID/FFI.pm

filter: Statementstmt 96.8% 92 / 95 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 96.0% 24 / 25 Podpod 100% 11 / 11 totaltotal 93.7% 134 / 143 CC 7 SCAR 4.4
CC
7
Cov
93%
__ANON__
3.3
new
3.0
type
2.0
CRAP 1.6
↑ Summary
1 package UUID::FFI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use FFI::Platypus 1.00;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use FFI::Platypus::Memory ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use FFI::CheckLib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use overload '<=>' => sub { $_[0]->compare($_[1]) },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 ▶ '""' => sub { shift->as_hex },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 0 ▶ bool => sub { 1 }, fallback => 1;
Subroutine __ANON__: not called CC=1 SCAR=0.2
13  
14 # TODO: as_bin or similar
15  
16 # ABSTRACT: Universally Unique Identifiers FFI style
17 1 our $VERSION = '0.11'; # VERSION
18  
19  
20 1 my $ffi = FFI::Platypus->new( api => 1 );
21  
22 1 ▶$ffi->lib(sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
23 1 my @lib = eval {
24 1 require Alien::libuuid;
25 0 Alien::libuuid->VERSION('0.05');
26 0 Alien::libuuid->dynamic_libs;
27 };
28 1 ▶ return @lib if @lib;
Branch: 1 branch
BranchTrueFalseTotal
if @lib 0 1 1
29 1 @lib = FFI::CheckLib::find_lib(
30 lib => 'uuid',
31 symbol => [
32 'uuid_generate_random',
33 'uuid_generate_time',
34 'uuid_unparse',
35 'uuid_parse',
36 'uuid_copy',
37 'uuid_clear',
38 'uuid_type',
39 'uuid_variant',
40 'uuid_time',
41 'uuid_is_null',
42 'uuid_compare',
43 ]
44 );
45 1 ▶ die "Unable to find system libuuid with required symbols. Try installing or upgrading Alien::libuuid"
Branch: 1 branch
BranchTrueFalseTotal
unless @lib 0 1 1
46 unless @lib;
47 1 return @lib;
48 1 });
49  
50 11 ▶$ffi->mangler(sub { "uuid$_[0]" });
Subroutine __ANON__: called CC=1 SCAR=0.0
51  
52 1 $ffi->attach( _generate_random => ['opaque'] => 'void' );
53 1 $ffi->attach( _generate_time => ['opaque'] => 'void' );
54 1 $ffi->attach( _unparse => ['opaque', 'opaque'] => 'void' );
55 1 $ffi->attach( _parse => ['string', 'opaque'] => 'int' );
56 1 $ffi->attach( _copy => ['opaque', 'opaque'] => 'void' );
57 1 $ffi->attach( _clear => ['opaque'] => 'void' );
58 1 $ffi->attach( _type => ['opaque'] => 'int' );
59 1 $ffi->attach( _variant => ['opaque'] => 'int' );
60 1 $ffi->attach( _time => ['opaque', 'opaque'] => 'time_t' );
61 1 $ffi->attach( _is_null => ['opaque'] => 'int' );
62 1 $ffi->attach( _compare => ['opaque', 'opaque'] => 'int' );
63  
64  
65 sub new
66 14 ▶{
Subroutine new: called CC=3 SCAR=11.0
Pod documented
67 14 my($class, $hex) = @_;
68 14 ▶ croak "usage: UUID::FFI->new($hex)" unless $hex;
Branch: 1 branch
BranchTrueFalseTotal
unless $hex 0 14 14
69 14 my $self = bless \FFI::Platypus::Memory::malloc(16), $class;
70 14 my $r = _parse($hex, $$self);
71 14 ▶ croak "$hex is not a valid hex UUID" if $r != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $r != 0 1 13 14
72 13 $self;
73 }
74  
75  
76 sub new_random
77 7 ▶{
Subroutine new_random: called CC=1 SCAR=0.0
Pod documented
78 7 my($class) = @_;
79 7 my $self = bless \FFI::Platypus::Memory::malloc(16), $class;
80 7 _generate_random->($$self);
81 7 $self;
82 }
83  
84  
85 sub new_time
86 2 ▶{
Subroutine new_time: called CC=1 SCAR=0.0
Pod documented
87 2 my($class) = @_;
88 2 my $self = bless \FFI::Platypus::Memory::malloc(16), $class;
89 2 _generate_time($$self);
90 2 $self;
91 }
92  
93  
94 sub new_null
95 2 ▶{
Subroutine new_null: called CC=1 SCAR=0.0
Pod documented
96 2 my($class) = @_;
97 2 my $self = bless \FFI::Platypus::Memory::malloc(16), $class;
98 2 _clear($$self);
99 2 $self;
100 }
101  
102  
103 3 ▶sub is_null { _is_null(${$_[0]}) }
Subroutine is_null: called CC=1 SCAR=0.0
Pod documented
104  
105  
106 sub clone
107 1 ▶{
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
108 1 my($self) = @_;
109 1 my $other = bless \FFI::Platypus::Memory::malloc(16), ref $self;
110 1 _copy($$other, $$self);
111 1 $other;
112 }
113  
114  
115 sub as_hex
116 35 ▶{
Subroutine as_hex: called CC=1 SCAR=0.0
Pod documented
117 35 my($self) = @_;
118 35 my $data = "x" x 36;
119 35 my $ptr = unpack 'L!', pack 'P', $data;
120 35 _unparse($$self, $ptr);
121 35 $data;
122 }
123  
124  
125 49 ▶sub compare { _compare( ${$_[0]}, ${$_[1]} ) }
Subroutine compare: called CC=1 SCAR=0.0
Pod documented
126  
127 1 my %type_map = (
128 1 => 'time',
129 4 => 'random',
130 );
131  
132  
133 sub type
134 4 ▶{
Subroutine type: called CC=2 SCAR=7.1
Pod documented
135 4 my($self) = @_;
136 4 my $r = _type($$self);
137 4 ▶ $type_map{$r} || croak "illegal type: $r";
Branch: 1 branch
BranchTrueFalseTotal
$type_map{$r} or croak("illegal type: $r") 4 0 4
138 }
139  
140 1 my @variant = qw( ncs dce microsoft other );
141  
142  
143 sub variant
144 2 ▶{
Subroutine variant: called CC=2 SCAR=7.1
Pod documented
145 2 my($self) = @_;
146 2 my $r = _variant($$self);
147 2 ▶ $variant[$r] || croak "illegal varient: $r";
Branch: 1 branch
BranchTrueFalseTotal
$variant[$r] or croak("illegal varient: $r") 2 0 2
148 }
149  
150  
151 sub time
152 1 ▶{
Subroutine time: called CC=1 SCAR=0.0
Pod documented
153 1 my($self) = @_;
154 1 _time($$self, undef);
155 }
156  
157 sub DESTROY
158 26 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
159 26 my($self) = @_;
160 26 FFI::Platypus::Memory::free($$self);
161 }
162  
163 1 1;
164  
165 __END__
↑ Summary