added $key and $value for columns in generated dataset
[MojoFacets.git] / lib / MojoFacets / Data.pm
index 761ded7..d967f97 100644 (file)
@@ -549,6 +549,8 @@ sub __all_filters {
        join(',', sort(@_), 'order', $order);
 }
 
+our ($out, $key,$value);
+
 sub __commit_path_code {
        my ( $path, $i, $code, $commit_changed ) = @_;
 
@@ -560,8 +562,7 @@ sub __commit_path_code {
                $$commit_changed->{$_}++;
                $loaded->{$path}->{data}->{items}->[$i]->{$_} = $update->{$_};
        }
-       warn "XX ",dump( $loaded->{$path}->{data}->{items}->[$i] );
-       warn "__commit_path_code $path ",dump( $update );
+       #warn "__commit_path_code $path $i ",dump( $update );
 }
 
 sub items {
@@ -669,7 +670,7 @@ sub items {
        if ( $commit ) {
 
                warn "# commit on ", $#$filtered + 1, " items:\n$code\n";
-               my $out;
+               ( $key, $value, $out ) = ( 'key', 'value' );
                foreach ( 0 .. $#$filtered ) {
                        my $i = $filtered->[$_];
                        __commit_path_code( $path, $i, $code, \$commit_changed );
@@ -702,9 +703,9 @@ sub items {
                                , $self->param('code_description')
                                , time()
                        );
-                       my $key = $self->param('code_depends');
-                       $key =~ s/,.+$//;
                        $key ||= 'key';
+                       $value ||= 'value';
+                       warn "key $key value $value";
                        my $items;
                        foreach my $n ( keys %$out ) {
                                my $i = { $key => [ $n ] };
@@ -714,7 +715,7 @@ sub items {
                                } elsif ( $ref eq 'ARRAY' ) {
                                        $i->{$_} = $out->{$n};
                                } elsif ( ! $ref ) {
-                                       $i->{value} = [ $out->{$n} ];
+                                       $i->{$value} = [ $out->{$n} ];
                                } else {
                                        $i->{_error} = [ dump($out->{$n}) ];
                                }
@@ -758,7 +759,7 @@ sub items {
        my $sorted_items;
        my $from_end = $sort eq 'd' ? $#$filtered : 0;
        my $test_changed;
-       my $out;
+       my ( $key, $value, $out ) = ( 'key', 'value' ); # XXX make local
        foreach ( 0 .. $limit ) {
                my $i = $_ + $offset;
                last unless defined $filtered->[$i];
@@ -769,7 +770,7 @@ sub items {
                        my $update;
                        eval $code;
                        if ( $@ ) {
-                               warn "ERROR evaling\n$code\n$@";
+                               warn "ERROR evaling $@", dump($code);
                                $self->stash('eval_error', $@) if $@;
                        } else {
                                warn "EVAL ",dump($update);