line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::InflateColumn::JSON2Object::Role::Storable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: simplified MooseX::Storage clone with enhanced JSON boolean handling |
4
|
|
|
|
|
|
|
our $VERSION = '0.907'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
2524339
|
use 5.014; |
|
5
|
|
|
|
|
28
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
2702
|
use Moose::Role; |
|
5
|
|
|
|
|
25349
|
|
|
5
|
|
|
|
|
23
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
30878
|
use DBIx::Class::InflateColumn::JSON2Object::Trait::NoSerialize; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
150
|
|
11
|
5
|
|
|
5
|
|
553
|
use JSON::MaybeXS; |
|
5
|
|
|
|
|
6130
|
|
|
5
|
|
|
|
|
343
|
|
12
|
5
|
|
|
5
|
|
2394
|
use String::CamelCase qw(camelize decamelize); |
|
5
|
|
|
|
|
2909
|
|
|
5
|
|
|
|
|
387
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
41
|
use Moose::Util::TypeConstraints; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
40
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
subtype 'InflateColumnJSONBool', as 'Ref'; |
17
|
|
|
|
|
|
|
coerce 'InflateColumnJSONBool', |
18
|
|
|
|
|
|
|
from 'Str', |
19
|
|
|
|
|
|
|
via { $_ ? JSON->true : JSON->false }; |
20
|
|
|
|
|
|
|
coerce 'InflateColumnJSONBool', |
21
|
|
|
|
|
|
|
from 'Int', |
22
|
|
|
|
|
|
|
via { $_ ? JSON->true : JSON->false }; |
23
|
|
|
|
|
|
|
coerce 'InflateColumnJSONBool', from 'Undef', via { JSON->false }; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub freeze { |
26
|
19
|
|
|
19
|
0
|
55
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
19
|
|
|
|
|
75
|
my $payload = $self->pack; |
29
|
19
|
|
|
|
|
150
|
my $json = JSON::MaybeXS->new->utf8->convert_blessed->encode($payload); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# stolen from MooseX::Storage |
32
|
19
|
50
|
33
|
|
|
586
|
utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); |
33
|
19
|
|
|
|
|
299
|
return $json; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub thaw { |
37
|
14
|
|
|
14
|
0
|
40
|
my ( $class, $payload ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# stolen from MooseX::Storage |
40
|
14
|
100
|
|
|
|
90
|
utf8::encode($payload) if utf8::is_utf8($payload); |
41
|
|
|
|
|
|
|
|
42
|
14
|
100
|
|
|
|
148
|
$payload = decode_json($payload) unless ref($payload); |
43
|
14
|
|
|
|
|
284
|
return $class->new($payload); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub pack { |
47
|
25
|
|
|
25
|
0
|
64
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
25
|
|
|
|
|
60
|
my $payload = {}; |
50
|
25
|
|
|
|
|
134
|
foreach my $attribute ( $self->meta->get_all_attributes ) { |
51
|
|
|
|
|
|
|
next |
52
|
64
|
50
|
|
|
|
2214
|
if $attribute->does( |
53
|
|
|
|
|
|
|
'DBIx::Class::InflateColumn::Trait::NoSerialize'); |
54
|
64
|
|
|
|
|
444167
|
my $val = $attribute->get_value($self); |
55
|
64
|
100
|
|
|
|
9494
|
next unless defined $val; |
56
|
|
|
|
|
|
|
|
57
|
57
|
|
|
|
|
2031
|
my $type = $attribute->type_constraint; |
58
|
57
|
100
|
100
|
|
|
605
|
if ($type && ($type eq 'Int' || $type eq 'Num')) { |
|
|
|
66
|
|
|
|
|
59
|
7
|
|
|
|
|
367
|
$val = 1 * $val; |
60
|
|
|
|
|
|
|
} |
61
|
57
|
|
|
|
|
4182
|
$payload->{ $attribute->name } = $val; |
62
|
|
|
|
|
|
|
} |
63
|
25
|
|
|
|
|
126
|
return $payload; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub moniker { |
67
|
2
|
|
|
2
|
0
|
7
|
my ($self) = @_; |
68
|
2
|
|
33
|
|
|
11
|
my $class = ref($self) || $self; |
69
|
2
|
|
|
|
|
16
|
$class =~ /::([^:]+)$/; |
70
|
2
|
|
|
|
|
13
|
return decamelize($1); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub package { |
74
|
6
|
|
|
6
|
0
|
102
|
my ( $class, $moniker ) = @_; |
75
|
6
|
|
|
|
|
30
|
return $class . '::' . camelize($moniker); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub TO_JSON { |
79
|
6
|
|
|
6
|
0
|
104
|
my $self = shift; |
80
|
6
|
|
|
|
|
18
|
return $self->pack; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding UTF-8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
DBIx::Class::InflateColumn::JSON2Object::Role::Storable - simplified MooseX::Storage clone with enhanced JSON boolean handling |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 VERSION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
version 0.907 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
DBIx::Class::InflateColumn::JSON2Object::Role::Storable - simplified MooseX::Storage clone with enhanced JSON boolean handling |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
version 0.900 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Thomas Klausner <domm@cpan.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Thomas Klausner. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Thomas Klausner <domm@plix.at> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2017 - 2021 by Thomas Klausner. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |