use CGI::AppEasy; use Getopt::Long; use Data::Dumper; use MIME::Base64; use HTTP::Daemon; use HTTP::Status; use strict; use warnings; my $dbfilename = 'stash.dat'; # always load existing, first: our $stash1 = {}; # this is the variable set by eval'ing the Dumper-generated code. my $fh; if ( open $fh, '<', $dbfilename ) { local $/; eval decode_base64( <$fh> ); close $fh; } my $static_content; make_main_content(); my $w = CGI::AppEasy->new( '/' => \$static_content, '/dump' => \&Dump, '/exit' => \&Exit, '/update' => \&Update, '/explore' => \&Explore, ); GetOptions( 'update!' => sub { shift; Update() }, 'dump!' => sub { shift; Dump() }, 'explorer!' => sub { shift; Explore() }, 'server!' => sub { $w->serve }, ); sub Dump { print Dumper $_[0]; print Dumper $stash1; $static_content } sub Update { my %entries = map { my( $title ) = /(.*)\.URL/i; my( $url ) = do { local(@ARGV,$/) = ($_); <> } =~ /^URL=(.*)/m; $url ? ( $url => $title ) : () } grep /\.URL$/i, do { opendir my $dh, '.' or die; readdir $dh }; keys %entries or die "Nothing new to add.\n"; warn "Adding these entries: \n\n", Dumper \%entries; @{$stash1}{keys %entries} = values %entries; # write it back out: open $fh, '>', $dbfilename or die; local $Data::Dumper::Indent=0; local $Data::Dumper::Varname='stash'; print $fh encode_base64( Dumper $stash1 ); close $fh; make_main_content(); $static_content } sub Explore { system qq(explorer .); $static_content } sub Exit { $_[1]->end; # this causes server loop exit. page_contain( qq(Return, if the server is running again, or close this browser window.
\n) ) } sub make_main_content { $static_content = page_contain( join '', # menu: qq( Main Update stash Open Explorer Exit the server loop