show dependent or all code snippets button
[MojoFacets.git] / lib / MojoFacets / Code.pm
index db4ad9f..0a523ef 100644 (file)
@@ -11,6 +11,9 @@ use File::Slurp;
 sub index {
        my $self = shift;
 
+       $self->redirect_to('/data/columns') unless $self->session('columns');
+       my $columns = { map { $_ => 1 } @{ $self->session('columns') } };
+
        my $dir = $self->app->home->rel_dir('public') . '/code';
 
        my $snippets;
@@ -18,8 +21,16 @@ sub index {
        foreach my $full_path ( glob("$dir/*.pl") ) {
                my $path = $full_path;
                $path =~ s/^$dir\/*//;
-               my ( $column, $description ) = split(/\./,$path,2);
-               $snippets->{$column}->{$description} = read_file $full_path;
+               $path =~ s/\.pl$//;
+               my ( $depends, $description ) = split(/\./,$path,2);
+
+               my @deps = split(/,/,$depends);
+               my $found = -1;
+               $found += $columns->{$_} foreach @deps;
+warn "# depends $depends $found $#deps\n";
+               next unless $found == $#deps || $self->param('all_code');
+
+               $snippets->{$depends}->{$description} = read_file $full_path, binmode => ':utf8';
        }
 
        $self->render(