Eve/PgSqlType/Array.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« Eve/ItemTestBase.pm ↑ Summary Eve/PgSqlType/Bigint.pm »
1 package Eve::PgSqlType::Array;
2  
3 9 ▶use parent qw(Eve::PgSqlType);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 use strict;
6 use warnings;
7  
8 use DateTime::Format::Pg;
9 use DBD::Pg ();
10  
11 =head1 NAME
12  
13 B<Eve::PgSqlType::Array> - a PostgreSQL array type.
14  
15 =head1 SYNOPSIS
16  
17 my $array = Eve::PgSqlType::Array->new();
18 my $text = $array->serialize(value => $some_array);
19 my $array_ref = $bigint->deserialize(value => $some_result);
20  
21 =head1 DESCRIPTION
22  
23 B<Eve::PgSqlType::Array> is a PostgreSQL array type adapter class.
24  
25 =head1 METHODS
26  
27 =head2 B<get_type()>
28  
29 =head3 Returns
30  
31 The PG_ANYARRAY type.
32  
33 =cut
34  
35 sub get_type {
36 return DBD::Pg::PG_ANYARRAY;
37 }
38  
39 =head2 B<wrap()>
40  
41 Wraps an expression with CAST statement.
42  
43 =head3 Arguments
44  
45 =over 4
46  
47 =item C<expression>
48  
49 =back
50  
51 =head3 Returns
52  
53 CAST (C<expression> AS array)
54  
55 =cut
56  
57 sub wrap {
58 my ($self, %arg_hash) = @_;
59 Eve::Support::arguments(\%arg_hash, my $expression);
60  
61 return 'CAST ('.$expression.' AS anyarray)';
62 }
63  
64 =head2 B<serialize()>
65  
66 Formats an array object into the appropriate string array
67 representation.
68  
69 =head3 Arguments
70  
71 =over 4
72  
73 =item C<value>
74  
75 =back
76  
77 =head3 Returns
78  
79 The string like '{all, array, values}'.
80  
81 =cut
82  
83 sub serialize {
84 my ($self, %arg_hash) = @_;
85 Eve::Support::arguments(\%arg_hash, my $value);
86  
87 return '{' . join(',', @{$value}) . '}';
88 }
89  
90 =head2 B<deserialize()>
91  
92 Just a passthrough method to return whatever value has been passed to it.
93  
94 =head3 Arguments
95  
96 =over 4
97  
98 =item C<value>
99  
100 =back
101  
102 =head3 Returns
103  
104 The value that is passed to the method.
105  
106 =cut
107  
108 sub deserialize {
109 my ($self, %arg_hash) = @_;
110 Eve::Support::arguments(\%arg_hash, my $value);
111  
112 return $value;
113 }
114  
115 =head1 SEE ALSO
116  
117 =over 4
118  
119 =item L<DBD::Pg>
120  
121 =item L<Eve::PgSqlType>
122  
123 =back
124  
125 =head1 LICENSE AND COPYRIGHT
126  
127 Copyright 2012 Igor Zinovyev.
128  
129 This program is free software; you can redistribute it and/or modify it
130 under the terms of either: the GNU General Public License as published
131 by the Free Software Foundation; or the Artistic License.
132  
133 See http://dev.perl.org/licenses/ for more information.
134  
135  
136 =head1 AUTHOR
137  
138 =over 4
139  
140 =item L<Igor Zinovyev|mailto:zinigor@gmail.com>
141  
142 =back
143  
144 =cut
145  
146 1;
« Eve/ItemTestBase.pm ↑ Summary Eve/PgSqlType/Bigint.pm »