line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UUID::FFI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
228077
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
41
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
703
|
use FFI::Platypus 1.00; |
|
1
|
|
|
|
|
7441
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
515
|
use FFI::Platypus::Memory (); |
|
1
|
|
|
|
|
13341
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
510
|
use FFI::CheckLib (); |
|
1
|
|
|
|
|
2918
|
|
|
1
|
|
|
|
|
33
|
|
9
|
1
|
|
|
1
|
|
7
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
10
|
24
|
|
|
24
|
|
71
|
use overload '<=>' => sub { $_[0]->compare($_[1]) }, |
11
|
1
|
|
|
1
|
|
427
|
'""' => sub { shift->as_hex }, |
12
|
1
|
|
|
1
|
|
7
|
bool => sub { 1 }, fallback => 1; |
|
1
|
|
|
0
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
|
0
|
|
|
|
|
0
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# TODO: as_bin or similar |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: Universally Unique Identifiers FFI style |
17
|
|
|
|
|
|
|
our $VERSION = '0.09'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $ffi = FFI::Platypus->new( api => 1 ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$ffi->lib(sub { |
23
|
|
|
|
|
|
|
my @lib = eval { |
24
|
|
|
|
|
|
|
require Alien::libuuid; |
25
|
|
|
|
|
|
|
Alien::libuuid->dynamic_libs; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
return @lib if @lib; |
28
|
|
|
|
|
|
|
return FFI::CheckLib::find_lib(lib => 'uuid'); |
29
|
|
|
|
|
|
|
}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$ffi->attach( [uuid_generate_random => '_generate_random'] => ['opaque'] => 'void' => '$' ); |
32
|
|
|
|
|
|
|
$ffi->attach( [uuid_generate_time => '_generate_time'] => ['opaque'] => 'void' => '$' ); |
33
|
|
|
|
|
|
|
$ffi->attach( [uuid_unparse => '_unparse'] => ['opaque', 'opaque'] => 'void' => '$$' ); |
34
|
|
|
|
|
|
|
$ffi->attach( [uuid_parse => '_parse'] => ['string', 'opaque'] => 'int' => '$$' ); |
35
|
|
|
|
|
|
|
$ffi->attach( [uuid_copy => '_copy'] => ['opaque', 'opaque'] => 'void' => '$$' ); |
36
|
|
|
|
|
|
|
$ffi->attach( [uuid_clear => '_clear'] => ['opaque'] => 'void' => '$' ); |
37
|
|
|
|
|
|
|
$ffi->attach( [uuid_type => '_type'] => ['opaque'] => 'int' => '$' ); |
38
|
|
|
|
|
|
|
$ffi->attach( [uuid_variant => '_variant'] => ['opaque'] => 'int' => '$' ); |
39
|
|
|
|
|
|
|
$ffi->attach( [uuid_time => '_time'] => ['opaque', 'opaque'] => 'time_t' => '$$' ); |
40
|
|
|
|
|
|
|
$ffi->attach( [uuid_is_null => '_is_null'] => ['opaque'] => 'int' => '$' ); |
41
|
|
|
|
|
|
|
$ffi->attach( [uuid_compare => '_compare'] => ['opaque', 'opaque'] => 'int' => '$$' ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new |
45
|
|
|
|
|
|
|
{ |
46
|
14
|
|
|
14
|
1
|
5743
|
my($class, $hex) = @_; |
47
|
14
|
50
|
|
|
|
26
|
croak "usage: UUID::FFI->new($hex)" unless $hex; |
48
|
14
|
|
|
|
|
55
|
my $self = bless \FFI::Platypus::Memory::malloc(16), $class; |
49
|
14
|
|
|
|
|
62
|
my $r = _parse($hex, $$self); |
50
|
14
|
100
|
|
|
|
213
|
croak "$hex is not a valid hex UUID" if $r != 0; |
51
|
13
|
|
|
|
|
28
|
$self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new_random |
56
|
|
|
|
|
|
|
{ |
57
|
7
|
|
|
7
|
1
|
14119
|
my($class) = @_; |
58
|
7
|
|
|
|
|
44
|
my $self = bless \FFI::Platypus::Memory::malloc(16), $class; |
59
|
7
|
|
|
|
|
384
|
_generate_random->($$self); |
60
|
7
|
|
|
|
|
57
|
$self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new_time |
65
|
|
|
|
|
|
|
{ |
66
|
2
|
|
|
2
|
1
|
1605
|
my($class) = @_; |
67
|
2
|
|
|
|
|
14
|
my $self = bless \FFI::Platypus::Memory::malloc(16), $class; |
68
|
2
|
|
|
|
|
293
|
_generate_time($$self); |
69
|
2
|
|
|
|
|
15
|
$self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new_null |
74
|
|
|
|
|
|
|
{ |
75
|
2
|
|
|
2
|
1
|
3442
|
my($class) = @_; |
76
|
2
|
|
|
|
|
16
|
my $self = bless \FFI::Platypus::Memory::malloc(16), $class; |
77
|
2
|
|
|
|
|
11
|
_clear($$self); |
78
|
2
|
|
|
|
|
7
|
$self; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
3
|
1
|
7
|
sub is_null { _is_null(${$_[0]}) } |
|
3
|
|
|
|
|
37
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub clone |
86
|
|
|
|
|
|
|
{ |
87
|
1
|
|
|
1
|
1
|
411
|
my($self) = @_; |
88
|
1
|
|
|
|
|
7
|
my $other = bless \FFI::Platypus::Memory::malloc(16), ref $self; |
89
|
1
|
|
|
|
|
5
|
_copy($$other, $$self); |
90
|
1
|
|
|
|
|
2
|
$other; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub as_hex |
95
|
|
|
|
|
|
|
{ |
96
|
35
|
|
|
35
|
1
|
2374
|
my($self) = @_; |
97
|
35
|
|
|
|
|
56
|
my $data = "x" x 36; |
98
|
35
|
|
|
|
|
95
|
my $ptr = unpack 'L!', pack 'P', $data; |
99
|
35
|
|
|
|
|
177
|
_unparse($$self, $ptr); |
100
|
35
|
|
|
|
|
168
|
$data; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
49
|
|
|
49
|
1
|
101
|
sub compare { _compare( ${$_[0]}, ${$_[1]} ) } |
|
49
|
|
|
|
|
64
|
|
|
49
|
|
|
|
|
133
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my %type_map = ( |
107
|
|
|
|
|
|
|
1 => 'time', |
108
|
|
|
|
|
|
|
4 => 'random', |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub type |
113
|
|
|
|
|
|
|
{ |
114
|
4
|
|
|
4
|
1
|
11
|
my($self) = @_; |
115
|
4
|
|
|
|
|
17
|
my $r = _type($$self); |
116
|
4
|
50
|
|
|
|
29
|
$type_map{$r} || croak "illegal type: $r"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my @variant = qw( ncs dce microsoft other ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub variant |
123
|
|
|
|
|
|
|
{ |
124
|
2
|
|
|
2
|
1
|
14
|
my($self) = @_; |
125
|
2
|
|
|
|
|
9
|
my $r = _variant($$self); |
126
|
2
|
50
|
|
|
|
18
|
$variant[$r] || croak "illegal varient: $r"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub time |
131
|
|
|
|
|
|
|
{ |
132
|
1
|
|
|
1
|
1
|
10
|
my($self) = @_; |
133
|
1
|
|
|
|
|
7
|
_time($$self, undef); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub DESTROY |
137
|
|
|
|
|
|
|
{ |
138
|
26
|
|
|
26
|
|
7374
|
my($self) = @_; |
139
|
26
|
|
|
|
|
123
|
FFI::Platypus::Memory::free($$self); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |