File Coverage

lib/MojoX/Mysql/Result.pm
Criterion Covered Total %
statement 12 49 24.4
branch 0 16 0.0
condition 0 21 0.0
subroutine 4 6 66.6
pod 0 2 0.0
total 16 94 17.0


line stmt bran cond sub pod time code
1             package MojoX::Mysql::Result;
2 7     7   32 use Mojo::Base -base;
  7         11  
  7         45  
3 7     7   1060 use Mojo::Util qw(dumper);
  7         11  
  7         389  
4 7     7   45 use Mojo::Collection 'c';
  7         12  
  7         362  
5 7     7   39 use Mojo::Date;
  7         10  
  7         44  
6              
7             sub async {
8 0     0 0   my ($self,$sth,$dbh,$cb) = @_;
9 0           sleep(0.01) until($sth->mysql_async_ready);
10 0           my $counter = $sth->mysql_async_result;
11 0           my $collection = $self->collection($sth,$cb);
12 0           $sth->finish;
13 0           $dbh->commit;
14 0           $dbh->disconnect;
15 0 0         return wantarray ? ($collection,$counter,$sth,$dbh) : $collection;
16             }
17              
18             sub collection {
19 0     0 0   my ($self,$sth,$cb) = @_;
20 0           my $collection = c();
21 0           my $names = $sth->{'NAME'};
22 0           my $types = $sth->{'mysql_type_name'};
23 0           my $nulls = $sth->{'NULLABLE'};
24             #my $scale = $sth->{'Statement'};
25              
26 0           while (my $ref = $sth->fetch()) {
27 0 0         if(ref($names) eq 'ARRAY'){
28 0           my %hash;
29 0           my $count_state = -1;
30 0           for(@{$names}){
  0            
31 0           $count_state++;
32 0           my $value = $ref->[$count_state];
33 0           my $type = $types->[$count_state];
34 0           my $null = $nulls->[$count_state];
35              
36 0 0 0       if($type eq 'tinyint' || $type eq 'smallint' || $type eq 'mediumint' || $type eq 'integer' || $type eq 'bigint'){
    0 0        
      0        
      0        
      0        
37 0 0 0       if($null == 1 && !defined $value){
38 0           $value = undef;
39             }
40             else{
41 0           $value = int $value;
42             }
43             }
44             elsif($type eq 'datetime' && defined $value){
45 0           $value = Mojo::Date->new($value);
46             }
47             else{
48 0 0 0       if(!$value && $null){
49 0           $value = undef;
50             }
51             else{
52 0           $value =~ s/^\s+|\s+$//g;
53 0 0         utf8::decode($value) unless utf8::is_utf8($value);
54             }
55             }
56 0           $hash{$_} = $value;
57             }
58 0 0         $self->$cb(\%hash) if(ref $cb eq 'CODE');
59 0           push(@{$collection}, \%hash);
  0            
60             }
61             }
62 0           return $collection;
63             }
64              
65              
66             1;
67