#!/usr/bin/perl #!__________________________________________.###@ #! ## #! Markup::Perl -> Review/Demo by usemodperl 07/01/2018 # #! | #! "For some problems, particularly in the presentation layer, | #! thinking of the solution as a webpage that can run perl is | #! more natural than thinking of it as a perl script that can | #! print a webpage." <- All quotes from Markup::Perl pod. .# #!____________________________________________________________.## #! # use strict; # Avoid dreaded traps. | use warnings; # Bug removal machine. | use ExtUtils::Installed; # CORE | use Pod::Simple::HTML; # CORE | use HTML::Entities; # CPAN .# #!____________________________________________________________.## #! # #! "It's a perl script when it starts. But as soon as the | #! following line is encountered the rules all change": | #! .# #! use Markup::Perl; # CPAN .## #!__________________________________________________________.###@ =head1 NAME Markup::Perl -> Review/Demo by usemodperl =head1 DESCRIPTION Markup::Perl promises to "turn your CGI inside-out" and the results are web programming paradise. This demo is a basic CGI shell. When not supplied with parameters it reads and prints its own pod as HTML and displays its source code in a textarea. It also prints the pod from Markup::Perl and displays its source in a textarea. Markup::Perl is extremely useful for rapid prototyping and creating single user CGI utilities. It parses and evals tags embedded in HTML in scripts that use the module, and recursively from external files. =head1 USAGE Run this demo as CGI to render HTML; or command line for raw output. =over =item CGI HTML form, and query string: ?cmd=pwd =item CLI perl this.pl cmd=pwd perl this.pl > that.html; open file:///path/to/that.html =back =head1 POWERS Recursive includes! Handle params and cookies! fatalsToBrowser built-in! =head1 QUIRKS For more about running code with eval see: perldoc -f eval. Recursive self-referential includes will result in busy zombies so try not to do anything like: src($0) Includes should not include themselves (or files that include them). Watch out for unclosed loops and tags. It's only an issue during development. =head1 TEMPLATE #!/usr/bin/perl use strict; use warnings; use Markup::Perl; print "Perl $^V" =head1 CONCLUSION =over =item Markup::Perl is powerful, productive and fun! L =back =head1 AUTHOR =over =item usemodperl L =back =cut # HERE COMES EVERYONE (PERL/HTML/CSS/JS): use Markup::Perl; # DEFINE PERL VARIABLES my $cmd = param('cmd') || ''; my $cfg = param('cfg') || ''; my $form = HTML::Entities::encode_entities($cmd) || ''; my $CPAN = 'https://metacpan.org/pod/Markup::Perl'; my $time = time; <perl> print $form ? "Perl $^V" : 'Markup::Perl CGI Demo'; </perl>
  🐪

# RUN SHELL COMMAND if ($cmd) { # TAINT A THING $_ = `$cmd`; print '
    ',
      HTML::Entities::encode_entities($_), '
' } # GENERATE DEFAULT DISPLAY else { # FIND MODULE FILE $_ = ExtUtils::Installed->new; @_ = $_->files("Markup::Perl"); @_ = grep/\.pm$/, @_; # READ MODULE AND SELF my $module = do{local(@ARGV,$/)=$_[0];<>}; my $self = do{local(@ARGV,$/)=$0;<>}; # SELF POD TO HTML my $spod = Pod::Simple::HTML->new; $spod->output_string(\my $shtml); $spod->parse_string_document($self); $shtml =~ s\^.*?(

.*?)\$1\s; # INSERT DEMO LINK INTO PERLDOC $shtml =~ s\(perldoc....eval)\ $1\sx; # NOT USUALLY POSSIBLE! :-) $shtml =~ s\(basic.....shell)\ $1\sx; # PRINT SELF POD print $shtml, '

SOURCE

', "

$0

", # PRINT SELF SOURCE '



'; # MODULE POD TO HTML my $mpod = Pod::Simple::HTML->new; $mpod->output_string(\my $mhtml); $mpod->parse_string_document($module); $mhtml =~ s\^.*?(

.*?)\$1\s; # REMOVE POD FROM SOURCE $module =~ s\__END__.*$\\s; # PRINT MODULE POD print $mhtml, '

SOURCE

', "

$_[0]

", # PRINT MODULE SOURCE '
', # PRINT PERL INFO '

perl -v

', `perl -v`, '
'; } # ADD HTTP HEADER header('X-Powered-By' => 'Perl'); # KISS PERL GOODBYE, FOR NOW



STOP REINVENTING WHEELS, START BUILDING SPACE ROCKETS! CPAN 🐪

#!_Markup::Perl -> Review/Demo________________________.usemodperl #! # #! "It's a perl script when it starts. But as soon as the | #! following line is encountered the rules all change": .# #!___________________________________________________________.### #! .# #! use Markup::Perl: https://metacpan.org/pod/Markup::Perl .## #!__________________________________________________________.###@