sub base_menu { my %opt = @_; my $directory = $opt{'directory'}; my $curr_cwd = cwd; my @contents = file_list($directory); @contents = grep {/^\p{uppercase}/} @contents if (!$opt{'full'} || $opt{'full'} !~ /^[yt1]/); # Thank you [tye]! # Thank you [davido]! my $sub = $directory =~ /(Other_poets|Player_characters|Spellbooks)$/ ? \&name_sort : \&article_sort; @contents = sort { $sub->($a, $b, { 'misc' => $opt{'misc'} }) } @contents; my (@files, @directories); for my $content (@contents) { my $long_content = "$directory/$content"; my $link = File::Spec->abs2rel($long_content); my $text = $content !~ /^\./ ? textify($content) : $content; if (-f $long_content) { my $active = realpath($0) eq $long_content ? 'active' : 'inactive'; my $color = $opt{'color'} == 1 ? link_color($content,1) : undef; my $inlist = $active eq 'active' && $opt{'file menu'} ? ['u', $opt{'file menu'}, { 'class' => 'sub_menu' }] : undef; $active .= $active eq 'active' && $opt{'file menu'} ? ' open' : ''; if (-M $long_content < 3) { $active .= ' updated'; } push @files, [anchor($text, { 'href' => $link, 'title' => $text, 'style' => $color }), { 'class' => $active, 'inlist' => $inlist } ]; } if (-d $long_content) { my $active = $curr_cwd =~ /$long_content/ ? 'open active' : 'closed inactive'; my $file_list; my $index = "$long_content/index.pl"; if (-e $index) { $link .= "/index.pl"; my $color = $opt{'color'} == 1 ? link_color($link,1) : undef; $text = anchor($text, { 'href' => $link, 'title' => $text, 'style' => $color }); $file_list = "$curr_cwd/$0" =~ /$index/ && $active =~ / active$/ && $opt{'file menu'} ? $opt{'file menu'} : undef; } my $next_list = base_menu( 'directory' => $long_content, 'color' => $opt{'color'}, 'full' => $opt{'full'}, 'misc' => $opt{'misc'}, 'file menu' => $opt{'file menu'} ); push @$next_list, @$file_list if $file_list; my $inlist = $next_list ? ['u', $next_list] : undef; $active =~ s/^(?:open|closed) // if !$inlist; push @directories, [$text, { 'class' => $active, 'inlist' => $inlist}]; } } my @file_lines = (@files, @directories); return @file_lines > 0 ? \@file_lines : undef; }