| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Types::ULID; |
|
2
|
|
|
|
|
|
|
$Types::ULID::VERSION = '0.002'; |
|
3
|
1
|
|
|
1
|
|
103403
|
use v5.10; |
|
|
1
|
|
|
|
|
3
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
532
|
use Type::Library -base; |
|
|
1
|
|
|
|
|
36382
|
|
|
|
1
|
|
|
|
|
10
|
|
|
8
|
1
|
|
|
1
|
|
810
|
use Types::Standard qw(Undef); |
|
|
1
|
|
|
|
|
75196
|
|
|
|
1
|
|
|
|
|
14
|
|
|
9
|
1
|
|
|
1
|
|
3020
|
use Types::Common::String qw(StrLength); |
|
|
1
|
|
|
|
|
62246
|
|
|
|
1
|
|
|
|
|
10
|
|
|
10
|
1
|
|
|
1
|
|
1558
|
use Data::ULID; |
|
|
1
|
|
|
|
|
580757
|
|
|
|
1
|
|
|
|
|
216
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $tr_alphabet = '0-9a-hjkmnp-tv-zA-HJKMNP-TV-Z'; |
|
13
|
|
|
|
|
|
|
my $ULID = Type::Tiny->new( |
|
14
|
|
|
|
|
|
|
name => 'ULID', |
|
15
|
|
|
|
|
|
|
parent => StrLength[26, 26], |
|
16
|
|
|
|
|
|
|
constraint => qq{ tr/$tr_alphabet// == 26 }, |
|
17
|
|
|
|
|
|
|
inlined => sub { |
|
18
|
|
|
|
|
|
|
my $varname = pop; |
|
19
|
|
|
|
|
|
|
return (undef, qq{ ($varname =~ tr/$tr_alphabet//) == 26 }); |
|
20
|
|
|
|
|
|
|
}, |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
coercion => [ |
|
23
|
|
|
|
|
|
|
Undef, q{ Data::ULID::ulid() }, |
|
24
|
|
|
|
|
|
|
], |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $BinaryULID = Type::Tiny->new( |
|
28
|
|
|
|
|
|
|
name => 'BinaryULID', |
|
29
|
|
|
|
|
|
|
parent => StrLength[16, 16], |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
coercion => [ |
|
32
|
|
|
|
|
|
|
Undef, q{ Data::ULID::binary_ulid() }, |
|
33
|
|
|
|
|
|
|
], |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->add_type($ULID); |
|
37
|
|
|
|
|
|
|
__PACKAGE__->add_type($BinaryULID); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__PACKAGE__->make_immutable; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Types::ULID - ULID type constraints |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Types::ULID qw(ULID BinaryULID); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# coercion from undef will generate new ulid |
|
52
|
|
|
|
|
|
|
has 'id' => ( |
|
53
|
|
|
|
|
|
|
is => 'ro', |
|
54
|
|
|
|
|
|
|
isa => ULID, |
|
55
|
|
|
|
|
|
|
coerce => 1, |
|
56
|
|
|
|
|
|
|
default => sub { undef }, |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Types::ULID is L<Type::Tiny> type for L<Data::ULID>. See |
|
62
|
|
|
|
|
|
|
L<https://github.com/ulid/spec> for ulid specification. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 Types |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head3 ULID |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Type for text (base32-encoded) ulid. Can be coerced from C<undef> - generates a new ulid. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head3 BinaryULID |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Type for binary ulid. Can be coerced from C<undef> - generates a new ulid. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
TODO: this does not currently check whether string contains multibyte characters. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L<Data::ULID> |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L<Type::Tiny> |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 AUTHOR |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Bartosz Jarzyna E<lt>bbrtj.pro@gmail.comE<gt> |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright (C) 2022 by Bartosz Jarzyna |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
91
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
92
|
|
|
|
|
|
|
|