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