Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / SQLAnywhere / Cursor.pm
CommitLineData
4b3515a6 1package DBIx::Class::Storage::DBI::SQLAnywhere::Cursor;
2
3use strict;
4use warnings;
5use base 'DBIx::Class::Storage::DBI::Cursor';
6use mro 'c3';
7
616ca57f 8use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
9use namespace::clean;
10
4b3515a6 11=head1 NAME
12
13DBIx::Class::Storage::DBI::SQLAnywhere::Cursor - GUID Support for SQL Anywhere
14over L<DBD::SQLAnywhere>
15
16=head1 DESCRIPTION
17
18This class is for normalizing GUIDs retrieved from SQL Anywhere via
19L<DBD::SQLAnywhere>.
20
21You probably don't want to be here, see
22L<DBIx::Class::Storage::DBI::SQLAnywhere> for information on the SQL Anywhere
23driver.
24
25Unfortunately when using L<DBD::SQLAnywhere>, GUIDs come back in binary, the
26purpose of this class is to transform them to text.
27L<DBIx::Class::Storage::DBI::SQLAnywhere> sets
28L<cursor_class|DBIx::Class::Storage::DBI/cursor_class> to this class by default.
29It is overridable via your
30L<connect_info|DBIx::Class::Storage::DBI/connect_info>.
31
32You can use L<DBIx::Class::Cursor::Cached> safely with this class and not lose
33the GUID normalizing functionality,
34L<::Cursor::Cached|DBIx::Class::Cursor::Cached> uses the underlying class data
35for the inner cursor class.
36
37=cut
38
a2f22854 39my $unpack_guids = sub {
40 my ($select, $col_infos, $data, $storage) = @_;
4b3515a6 41
42 for my $select_idx (0..$#$select) {
a2f22854 43 next unless (
44 defined $data->[$select_idx]
45 and
46 length($data->[$select_idx]) == 16
47 );
4b3515a6 48
a2f22854 49 my $selected = $select->[$select_idx];
4b3515a6 50
a2f22854 51 my $data_type = $col_infos->{$select->[$select_idx]}{data_type}
52 or next;
4b3515a6 53
a2f22854 54 $data->[$select_idx] = $storage->_uuid_to_str($data->[$select_idx])
55 if $storage->_is_guid_type($data_type);
4b3515a6 56 }
a2f22854 57};
4b3515a6 58
4b3515a6 59
a2f22854 60sub next {
61 my $self = shift;
4b3515a6 62
a2f22854 63 my @row = $self->next::method(@_);
4b3515a6 64
a2f22854 65 $unpack_guids->(
66 $self->args->[1],
616ca57f 67 $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
a2f22854 68 \@row,
69 $self->storage
70 );
4b3515a6 71
a2f22854 72 return @row;
73}
4b3515a6 74
a2f22854 75sub all {
76 my $self = shift;
4b3515a6 77
a2f22854 78 my @rows = $self->next::method(@_);
4b3515a6 79
a2f22854 80 $unpack_guids->(
81 $self->args->[1],
616ca57f 82 $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]),
a2f22854 83 $_,
84 $self->storage
85 ) for @rows;
4b3515a6 86
4b3515a6 87
88 return @rows;
89}
90
a2bd3796 91=head1 FURTHER QUESTIONS?
4b3515a6 92
a2bd3796 93Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
4b3515a6 94
a2bd3796 95=head1 COPYRIGHT AND LICENSE
4b3515a6 96
a2bd3796 97This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
98by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
99redistribute it and/or modify it under the same terms as the
100L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
4b3515a6 101
102=cut
a2bd3796 103
1041;
105
4b3515a6 106# vim:sts=2 sw=2: