lib/Data/UUID/Base64URLSafe.pm

filter: Statementstmt 100% 32 / 32 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 97.9% 48 / 49 CC 2 SCAR 1.7
CC
2
Cov
97%
from_b64_urlsafe
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Data::UUID::Base64URLSafe;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = "0.35";
8  
9 2 ▶use base qw( Data::UUID );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our @EXPORT = @Data::UUID::EXPORT;
11  
12 =encoding utf-8
13  
14 =head1 NAME
15  
16 Data::UUID::Base64URLSafe - getting Data::UUID with URLSafe strings
17  
18 =head1 SYNOPSIS
19  
20 use Data::UUID::Base64URLSafe;
21 my $ug = Data::UUID::Base64URLSafe->new();
22 my $uuid = $ug->create_b64_urlsafe(); # make an unique UUID
23 $uuid = $ug->create_from_name_b64_urlsafe( <namespace>, <string> ); # from namespace and string
24 my $str = $ug->from_b64_urlsafe(< Base64-URLSafe || Base64 >); # decoding from Base64
25 my $bin = $ug->create_from_name( <namepace>, <string> );
26 my $uuid2 = $ug->to_b64_urlsafe($bin); # encoding from binary
27  
28 =head1 DESCRIPTION
29  
30 Data::UUID::Base64URLSafe is a wrapper module for Data::UUID.
31  
32 L<Data::UUID|https://github.com/rjbs/Data-UUID> creates wonderful Globally/Universally Unique
33 Identifiers (GUIDs/UUIDs). This module is a subclass of that
34 module which adds a method to get a URL-safe Base64-encoded
35 version of the UUID using L<MIME::Base64|https://github.com/gisle/mime-base64>.
36 What that means is that you can get a 22-character UUID string which
37 you can use safely in URLs.
38  
39 It will help you when you wanna make user-ID on your web applications.
40  
41 =head1 METHODS
42  
43 =head2 new
44  
45 =cut
46  
47 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
48 1 my $class = shift;
49 1 return bless $class->SUPER::new(), $class;
50 };
51  
52 =head2 create_b64_urlsafe
53  
54 Create a URL-safe Base64-encoded UUID:
55  
56 my $uuid = $ug->create_b64_urlsafe();
57  
58 =cut
59  
60 2 ▶sub create_b64_urlsafe {
Subroutine create_b64_urlsafe: called CC=1 SCAR=0.0
Pod documented
61 2 my $self = shift;
62 2 my $uuid = $self->create();
63 2 return MIME::Base64::encode_base64url($uuid);
64 }
65  
66 =head2 create_from_name_b64_urlsafe
67  
68 Creates a URL-safe Base64 encoded UUID with the namespace and data
69 specified (See the L<Data::UUID|https://github.com/rjbs/Data-UUID> docs on create_from_name
70  
71 =cut
72  
73 1 ▶sub create_from_name_b64_urlsafe {
Subroutine create_from_name_b64_urlsafe: called CC=1 SCAR=0.0
Pod documented
74 1 my $self = shift;
75 1 my $uuid = $self->create_from_name(@_);
76 1 return MIME::Base64::encode_base64url($uuid);
77 }
78  
79 =head2 from_b64_urlsafe
80  
81 Convert a (URL-safe or not) Base64-encoded UUID to its canonical binary representation
82  
83 my $uuid = $ug−>create_from_name_b64_urlsafe(<namespace>, <name>);
84 my $bin = $ug->from_b64_urlsafe($uuid);
85  
86 =cut
87  
88 1 ▶sub from_b64_urlsafe {
Subroutine from_b64_urlsafe: called CC=2 SCAR=7.0
Pod documented
89 1 my $self = shift;
90 1 my $b64 = shift;
91 1 ▶ $b64 =~ tr[-_][+/] if $b64 =~ m|[-_]|;
Branch: 1 branch
BranchTrueFalseTotal
if $b64 =~ /[-_]/ 0 1 1
92 1 return MIME::Base64::decode_base64($b64);
93 }
94  
95 =head2 to_b64_urlsafe
96  
97 Convert a binary UUID to a URL-safe Base64 encoded UUID
98  
99 my $bin = $ug->create_from_name(<namespace>, <name>);
100 my $uuid = $ug−>to_b64_urlsafe($bin);
101  
102 =cut
103  
104 1 ▶sub to_b64_urlsafe {
Subroutine to_b64_urlsafe: called CC=1 SCAR=0.0
Pod documented
105 1 my $self = shift;
106 1 my $bin = shift;
107 1 return MIME::Base64::encode_base64url($bin);
108 }
109  
110 2 1;
111 __END__
↑ Summary