more sane intro-data structure link construction
[scpubgit/JSON-Tree-Viewer.git] / br.pl
diff --git a/br.pl b/br.pl
index 8f29ef2..2c63bd1 100644 (file)
--- a/br.pl
+++ b/br.pl
@@ -5,6 +5,7 @@ use Module::Runtime qw(use_module);
 use Scalar::Util qw(blessed);
 use IO::All;
 use JSON;
+use URI::Escape;
 
 has root => (is => 'lazy');
 
@@ -154,7 +155,7 @@ sub mangle_structure {
 sub link_to {
   my ($self, @to) = @_;
   use HTML::Tags;
-  s/\//\./g for my @link = @to;
+  my @link = map uri_escape(uri_escape($_)), @to;
   my $link = join('/', @link, '');
   my $to = $to[-1];
   my $html = join '', HTML::Tags::to_html_string(
@@ -170,8 +171,8 @@ sub descend {
     $target = $self->json->decode(scalar $target->all);
   }
   return $target unless @path;
-  (my $undot = my $step = shift @path) =~ s/\./\//g;
-  $self->descend($target->{$step}||$target->{$undot}, @path);
+  my $step = uri_unescape(uri_unescape( shift @path));
+  $self->descend($target->{$step}, @path);
 }
 
 sub render_table {
@@ -203,10 +204,13 @@ sub render_table {
 sub render_el {
   my ($self, $whole, $key, $part) = @_;
   if (ref($part) eq 'ARRAY') {
-    if ($key eq 'entries') {
-      if (grep { ref($_) eq 'HASH' } @$part) {
+    if (grep { ref($_) eq 'HASH' } @$part) {
+      if ($whole->{key}) {
+        return $self->link_to($whole->{key})
+      } elsif ($whole->{name}) {
         return $self->link_to($whole->{name}, $key);
       }
+      $part = '(complex)';
     }
     return join(', ', @$part);
   }