all code just loads snippets without dependencies
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 15 Jan 2011 13:02:01 +0000 (14:02 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 15 Jan 2011 13:02:01 +0000 (14:02 +0100)
before it also tried to test them, and transfer (non-existant) dependency
information and description both of which are (probably) wrong because
you just want to modify that code snippet to fit current dataset

lib/MojoFacets/Code.pm
templates/code/index.html.ep

index 352fb97..29b4a76 100644 (file)
@@ -23,6 +23,7 @@ sub index {
        my $dir = $self->_code_dir;
 
        my $snippets;
+       my $no_deps;
 
        foreach my $full_path ( glob("$dir/*.pl") ) {
                my $path = $full_path;
@@ -34,13 +35,19 @@ sub index {
                my $found = -1;
                $found += $columns->{$_} foreach @deps;
 warn "# depends $depends $found $#deps\n";
-               next unless $found == $#deps || $self->param('all_code');
+
+               if ( $found != $#deps ) {
+                       $self->param('all_code') ? $no_deps->{$depends}->{$description}++ : next;
+               }
 
                $snippets->{$depends}->{$description} = read_file $full_path, binmode => ':utf8';
        }
 
+warn "# no_deps ",dump($no_deps);
+
        $self->render(
                snippets => $snippets,
+               no_deps => $no_deps,
        );
 }
 
index b634c74..8be7d3d 100644 (file)
@@ -18,13 +18,16 @@ column in this dataset
 <h2><%= $depends %></h2>
 <ul>
 %   foreach my $desc ( keys %{ $snippets->{$depends} } ) {
+%    my $have_deps = ! exists $no_deps->{$depends}->{$desc};
 <li>
 <form method=post action=/data/items>
-<input type=submit name=test value="Load and test">
+<input type=submit name=test value="<%= $have_deps ? 'Load and test' : 'Load' %>">
 % my $path = "$depends.$desc.pl";
 <a target=code href="/code/<%= $path %>"><%= $desc %></a>
+% if ( $have_deps ) {
 <input type=hidden name=code_depends value="<%= $depends %>">
 <input type=hidden name=code_description value="<%= $desc %>">
+% }
 <a class=remove href="<%= url_for( action => 'remove' )->query( path => $path ) %>">remove</a>
 <br>
 % my $code = $snippets->{$depends}->{$desc};