File Coverage

blib/lib/DBIx/Class/Storage/DBI/SQLAnywhere/Cursor.pm
Criterion Covered Total %
statement 18 26 69.2
branch n/a
condition 0 6 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 26 42 61.9


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