package Markup::Perl; # $Id: Perl.pm,v 1.3 2006/09/04 15:30:15 michael Exp $ our $VERSION = '0.5'; use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser set_message); my %headers = (-type=>'text/html', -cookie=>[], -charset=>'UTF-8'); # defaults my $output = ''; my $print_start = ";\nprint substr(<<'mupl_EOS', 0, -1);\n"; my $print_end = "\nmupl_EOS\n"; my $in_file = $0; BEGIN { # catch prints into a variable, and dump at the end { package Buffer; sub TIEHANDLE { my ($class, $b) = @_; bless $b => $class; } sub PRINT { my $b = shift; $$b .= join '', @_; } sub PRINTF { my $b = shift; my $fm = shift; $$b .= sprintf($fm, @_);} } tie *STDOUT=>"Buffer", \$output; set_message(sub{ # for pretty CGI::Carp output my $message = shift; $message =~ s!<SCRIPT>!$in_file!g; $output = qq{\n\n

There was an error with "$in_file"
$message

}; }); } sub import { # when we are used my ($package, undef, $line) = caller(); $line or die "can't invoke from command-line\n"; open SCRIPT, "<$0" or die qq(can't open calling file "$0": $!); for (1..$line) { " tag from within a JavaScript block. <perl> print '<'.'/perl>'; =item including yourself It is possible to include and run Markup::Perl code from other files using the C function. This will lead to a recursive loop if a file included in such a way also includes a file which then includes itself. This is the same as using the Perl C function in such a way, and it's left to the programmer to avoid doing this. =item use utf8 I've made every effort to write code that is UTF-8 friendly. So much so that you are likely to experience more problems for B using UTF-8. Saving your documents as UTF-8 (no BOM) is recommended; other settings may or may not work. Files included via the C function are B assumed to be UTF-8. =back =head1 COPYRIGHT The author does not claim copyright on any part of this code; unless otherwise licensed, code in this work should be considered Public Domain. =head1 AUTHORS Michael Mathews , inspired by !WAHa.06x36 . =cut