blib/lib/UUID/URandom.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 100% 34 / 34 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package UUID::URandom;
6 # ABSTRACT: UUIDs based on /dev/urandom or the Windows Crypto API
7  
8 1 our $VERSION = '0.001';
9  
10 1 ▶use Exporter 5.57 qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Crypt::URandom 0.36 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our @EXPORT_OK = qw(
14 create_uuid
15 create_uuid_hex
16 create_uuid_string
17 );
18  
19 #pod =func create_uuid
20 #pod
21 #pod my $uuid = create_uuid();
22 #pod
23 #pod # "\x95\x5a\xe4\x96\x8b\xb2\x45\x0b\x9c\x7e\x99\xf5\x01\xdf\x90\xfe"
24 #pod
25 #pod This returns a new UUID as a 16 byte 'binary' string.
26 #pod
27 #pod =cut
28  
29 10003 ▶sub create_uuid {
Subroutine create_uuid: called CC=1 SCAR=0.0
Pod documented
30 10003 my $uuid = Crypt::URandom::urandom(16);
31 10003 vec( $uuid, 13, 4 ) = 0x4; # set UUID version
32 10003 vec( $uuid, 35, 2 ) = 0x2; # set UUID variant
33 10003 return $uuid;
34 }
35  
36 #pod =func create_uuid_hex
37 #pod
38 #pod my $uuid = create_uuid_hex();
39 #pod
40 #pod # "955ae4968bb2450b9c7e99f501df90fe"
41 #pod
42 #pod This returns a new UUID as a 32-byte hexadecimal string.
43 #pod
44 #pod =cut
45  
46 1 ▶sub create_uuid_hex {
Subroutine create_uuid_hex: called CC=1 SCAR=0.0
Pod documented
47 1 return unpack( "H*", create_uuid() );
48 }
49  
50 #pod =func create_uuid_string
51 #pod
52 #pod my $uuid = create_uuid_string();
53 #pod
54 #pod # "955ae496-8bb2-450b-9c7e-99f501df90fe"
55 #pod
56 #pod This returns a new UUID in the 36-byte RFC-4122 canonical string
57 #pod representation. (N.B. The canonical representation is lower-case.)
58 #pod
59 #pod =cut
60  
61 1 ▶sub create_uuid_string {
Subroutine create_uuid_string: called CC=1 SCAR=0.0
Pod documented
62 1 return join "-", unpack( "H8H4H4H4H12", create_uuid() );
63 }
64  
65 1 1;
66  
67  
68 # vim: ts=4 sts=4 sw=4 et tw=75:
69  
70 __END__
↑ Summary