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   25 use Mojo::Base -base;
  7         9  
  7         36  
3 7     7   719 use Mojo::Util qw(dumper);
  7         10  
  7         245  
4 7     7   35 use Mojo::Collection 'c';
  7         8  
  7         265  
5 7     7   23 use Mojo::Date;
  7         8  
  7         35  
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              
25 0           while (my $ref = $sth->fetch()) {
26 0 0         if(ref($names) eq 'ARRAY'){
27 0           my %hash;
28 0           my $count_state = -1;
29 0           for(@{$names}){
  0            
30 0           $count_state++;
31 0           my $value = $ref->[$count_state];
32 0           my $type = $types->[$count_state];
33 0           my $null = $nulls->[$count_state];
34              
35 0 0 0       if($type eq 'tinyint' || $type eq 'smallint' || $type eq 'mediumint' || $type eq 'integer' || $type eq 'bigint'){
    0 0        
      0        
      0        
      0        
36 0 0 0       if($null == 1 && !defined $value){
37 0           $value = undef;
38             }
39             else{
40 0           $value = int $value;
41             }
42             }
43             elsif($type eq 'datetime' && defined $value){
44 0           $value = Mojo::Date->new($value);
45             }
46             else{
47 0 0 0       if(!$value && $null){
48 0           $value = undef;
49             }
50             else{
51 0           $value =~ s/^\s+|\s+$//g;
52 0 0         utf8::decode($value) unless utf8::is_utf8($value);
53             }
54             }
55 0           $hash{$_} = $value;
56             }
57 0 0         $self->$cb(\%hash) if(ref $cb eq 'CODE');
58 0           push(@{$collection}, \%hash);
  0            
59             }
60             }
61 0           return $collection;
62             }
63              
64              
65             1;
66