From: Tim Bunce Date: Wed, 19 Sep 2012 14:24:26 +0000 (+0100) Subject: basic attribute pass-thru X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f60f09e5b8f639c255e83387770f4af0daf1e679;p=p5sagit%2FDevel-Size.git basic attribute pass-thru --- diff --git a/memnodes.pl b/memnodes.pl index 0ac6617..3681e03 100644 --- a/memnodes.pl +++ b/memnodes.pl @@ -5,6 +5,7 @@ use warnings; use DBI; use DBD::SQLite; +use JSON::XS; use Getopt::Long; @@ -13,6 +14,8 @@ GetOptions( 'db=s' => \my $opt_db, ) or exit 1; +my $j = JSON::XS->new->ascii->pretty(0); + my $dbh = DBI->connect("dbi:SQLite:dbname=$opt_db","","", { RaiseError => 1, PrintError => 0, AutoCommit => 0 }); @@ -28,11 +31,12 @@ $dbh->do(q{ self_size integer, kids_size integer, kids_node_count integer, - child_ids text + child_ids text, + attr_json text ) }); my $node_ins_sth = $dbh->prepare(q{ - INSERT INTO node VALUES (?,?,?,?, ?,?,?,?) + INSERT INTO node VALUES (?,?,?,?, ?,?,?,?,?) }); my @stack; @@ -68,10 +72,12 @@ sub leave_node { print qq(], "data":{ "\$area": $size } },\n); } if ($dbh) { + my $attr_json = $j->encode($x->{attr}); $node_ins_sth->execute( $x->{id}, $x->{name}, $x->{depth}, $x->{parent_id}, $x->{self_size}, $x->{kids_size}, $x->{kids_node_count}, - $x->{child_id} ? join(",", @{$x->{child_id}}) : undef + $x->{child_id} ? join(",", @{$x->{child_id}}) : undef, + $attr_json, ); # XXX attribs } diff --git a/static/MemView.pl b/static/MemView.pl index 2133621..fa4affc 100755 --- a/static/MemView.pl +++ b/static/MemView.pl @@ -3,6 +3,7 @@ use strict; use warnings; +use JSON::XS; use Mojolicious::Lite; use ORLite { @@ -13,6 +14,8 @@ use ORLite { #unicode => 1, }; +my $j = JSON::XS->new; + # Documentation browser under "/perldoc" plugin 'PODRenderer'; @@ -52,6 +55,7 @@ sub _fetch_node_tree { my ($id, $depth) = @_; my $node = MemView->selectrow_hashref("select * from node where id = ?", undef, $id) or die "Node '$id' not found"; + $node->{attr}{self} = $j->decode(delete $node->{attr_json}); if ($node->{child_ids}) { my @child_ids = split /,/, $node->{child_ids}; my $children; @@ -63,6 +67,8 @@ sub _fetch_node_tree { $child->{name} = "$node->{name} + $child->{name}"; $child->{$_} += $node->{$_} for (qw(self_size)); $child->{$_} = $node->{$_} for (qw(parent_id)); + Dwarn $node; + $child->{attr}{$node->{id}} = $node->{attr}; $child->{_ids_merged} .= ",$node->{id}"; my @child_ids = split /,/, $node->{child_ids}; diff --git a/static/public/.tm.js.swp b/static/public/.tm.js.swp index b590f45..041222f 100644 Binary files a/static/public/.tm.js.swp and b/static/public/.tm.js.swp differ diff --git a/static/public/tm.js b/static/public/tm.js index 44230ee..7dde7e9 100644 --- a/static/public/tm.js +++ b/static/public/tm.js @@ -107,7 +107,7 @@ function init(){ html += sprintf("Depth: %d
", data.depth); html += sprintf("Parent: %d
", data.parent_id); html += sprintf("Id: %s%s
", node.id, data._ids_merged ? data._ids_merged : ""); - //html += JSON.stringify(data, undefined, 4); + html += JSON.stringify(data.attr, undefined, 4); tip.innerHTML = html; }