line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PGObject::Type::ByteString; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
122319
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
31
|
use 5.008; |
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
8
|
1
|
|
|
1
|
|
399
|
use DBD::Pg qw(:pg_types); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
PGObject::Type::ByteString - Wrapper for raw strings mapping to BYTEA columns |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 1.1.1 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '1.1.1'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
PGObject::Type::ByteString->register(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Now all BYTEA columns will be returned as ByteString objects. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module provides a basic wrapper around Perl strings, mapping them to |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 register |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
By default registers PG_BYTEA |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub register { |
42
|
|
|
|
|
|
|
my $self = shift @_; |
43
|
|
|
|
|
|
|
croak "Can't pass reference to register \n". |
44
|
|
|
|
|
|
|
"Hint: use the class instead of the object" if ref $self; |
45
|
|
|
|
|
|
|
my %args = @_; |
46
|
|
|
|
|
|
|
my $registry = $args{registry}; |
47
|
|
|
|
|
|
|
$registry ||= 'default'; |
48
|
|
|
|
|
|
|
my $types = $args{types}; |
49
|
|
|
|
|
|
|
$types = [ DBD::Pg::PG_BYTEA, 'bytea' ] unless defined $types and @$types; |
50
|
|
|
|
|
|
|
for my $type (@$types){ |
51
|
|
|
|
|
|
|
my $ret = |
52
|
|
|
|
|
|
|
PGObject->register_type(registry => $registry, pg_type => $type, |
53
|
|
|
|
|
|
|
perl_class => $self); |
54
|
|
|
|
|
|
|
return $ret unless $ret; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 new |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
66
|
|
|
|
|
|
|
my ($class, $value) = @_; |
67
|
|
|
|
|
|
|
my $self; |
68
|
|
|
|
|
|
|
croak 'Must pass scalar or scalar ref' |
69
|
|
|
|
|
|
|
if defined ref $value and ref $value !~ /SCALAR/; |
70
|
|
|
|
|
|
|
if (ref $value ) { |
71
|
|
|
|
|
|
|
$self = $value; |
72
|
|
|
|
|
|
|
} else { |
73
|
|
|
|
|
|
|
$self = \$value; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
return bless $self, $class; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 from_db |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Parses a date from YYYY-MM-DD format and generates the new object based on it. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub from_db { |
86
|
|
|
|
|
|
|
my ($class, $value) = @_; |
87
|
|
|
|
|
|
|
return $class->new($value); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 to_db |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns the date in YYYY-MM-DD format. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub to_db { |
97
|
|
|
|
|
|
|
my ($self) = @_; |
98
|
|
|
|
|
|
|
# hashref with value and type allows us to tell DBD::Pg to bind to binary |
99
|
|
|
|
|
|
|
return { value => $$self, type => PG_BYTEA }; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Erik Huelsmann, C<< >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 BUGS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
109
|
|
|
|
|
|
|
C, or through |
110
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
111
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SUPPORT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
perldoc PGObject::Type::ByteString |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
You can also look for information at: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 4 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * CPAN Ratings |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * Search CPAN |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright 2016 Erik Huelsmann |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is released under the following license: BSD |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; # End of PGObject::Type::DateTime |