Modify your data using perl snippets
-Experimental REPL console supports perl snippets which get $rec hash which is one
+Experimental REPL console supports perl snippets which get $row hash which is one
element from your dataset. All values are repetable, so you always have to create
array of values if you are creating new columns, even for single value.
* generate new columns with number of elements in some other column
- $rec->{count} = [ $#{ $rec->{original} } + 1 ];
+ $row->{count} = [ $#{ $row->{original} } + 1 ];
* generate century column from year
- foreach my $year ( @{ $rec->{Year} } ) {
- push @{ $rec->{century} }, int($year/100)+1;
+ foreach my $year ( @{ $row->{Year} } ) {
+ push @{ $row->{century} }, int($year/100)+1;
}
* modify existing column
if ( $code && ( $test || $commit ) ) {
# XXX find columns used in code snippet and show them to user
- foreach my $column ( $code =~ m/\$rec->{(.+?)}/g ) {
+ foreach my $column ( $code =~ m/\$row->{(.+?)}/g ) {
if ( $column =~ s/^(['"])// ) {
$column =~ s/$1$//;
}
warn "# commit on ", $#$filtered + 1, " items:\n$code\n";
foreach ( 0 .. $#$filtered ) {
my $i = $filtered->[$_];
- my $rec = $data->{items}->[$i];
+ my $row = $data->{items}->[$i];
eval $code;
}
}
last unless defined $filtered->[$i];
$i = $from_end - $i if $from_end;
my $id = $filtered->[$i];
- my $rec = $data->{items}->[ $id ];
- $rec->{_row_id} ||= $id;
+ my $row = $data->{items}->[ $id ];
if ( $code && $test ) {
- $rec = Storable::dclone $rec;
+ $row = Storable::dclone $row;
eval $code;
if ( $@ ) {
warn "ERROR evaling\n$code\n$@";
$self->stash('eval_error', $@) if $@;
} else {
- warn "EVAL ",dump($rec);
+ warn "EVAL ",dump($row);
}
}
- push @$sorted_items, $rec;
+ $row->{_row_id} ||= $id;
+ push @$sorted_items, $row;
}
warn "# sorted_items ", $#$sorted_items + 1, " offset $offset limit $limit order $sort";
% layout 'default';
% my $action = $uid;
-% $action =~ s/^.+\.([^\.]+)$/$1/;
-% $action = url_for( controller => 'data', action => $action );
+% $action =~ s!\.!/!g;
+% $action =~ s!^\d+/\d+!!;
<form method=post action=<%= $action %>>
<input type=submit value="<%= $action %>">
<tt><%= $uid %></tt>