support various $out values
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 22 Jun 2010 13:23:50 +0000 (15:23 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 22 Jun 2010 13:25:37 +0000 (15:25 +0200)
This allows us to create datasets from scalars, arrays and hashes

lib/MojoFacets/Data.pm

index 9afa1d0..c532142 100644 (file)
@@ -656,6 +656,7 @@ sub items {
                        my $commit_dataset = join('.'
                                , $self->param('code_depends')
                                , $self->param('code_description')
+                               , time()
                        );
                        my $key = $self->param('code_depends');
                        $key =~ s/,.+$//;
@@ -663,7 +664,16 @@ sub items {
                        my $items;
                        foreach my $n ( keys %$out ) {
                                my $i = { $key => [ $n ] };
-                               $i->{$_} = [ $out->{$n}->{$_} ] foreach keys %{ $out->{$n} };
+                               my $ref = ref $out->{$n};
+                               if ( $ref eq 'HASH' ) {
+                                       $i->{$_} = [ $out->{$n}->{$_} ] foreach keys %{ $out->{$n} };
+                               } elsif ( $ref eq 'ARRAY' ) {
+                                       $i->{$_} = $out->{$n};
+                               } elsif ( ! $ref ) {
+                                       $i->{value} = [ $out->{$n} ];
+                               } else {
+                                       $i->{_error} = [ dump($out->{$n}) ];
+                               }
                                push @$items, $i;
                        };
                        undef $out;