Its a perl script when it starts. But as soon as the following line is encountered the rules all change.
Every line after that follows this new rule: Anything inside <perl>...</perl> tags will be executed as perl. Anything not inside <perl>...</perl> tags will be printed as is.
Is functionally equivalent to...
If you bear that in mind, you can see that this is also possible...
Naturally, anything you can do in an ordinary perl script you can also do inside <perl></perl> tags. Use your favourite CPAN modules, define your own, whatever.
If you would like to have a some shared Markup::Perl code in a separate file, simply include it like so...
The included file can have the same mixture of literal text and <perl> tags allowed in the first file, and can even include other Markup::Perl files using its own src() calls. Lexical my variables defined in src files are independent of and inaccessible to code in the original file. Package variables are accessible across src files by using the variables full package name.
|print order||Not all output happens in a stream-like way, but rather there is an attempt to be slightly intelligent by reordering certain things, such as printing of HTTP headers (including cookies). Thus you can use the header() call anywhere in your code, even conditionally, but the actual header, if you do print it, will always be at the very start of your document.|
header(name=>value) Adds the given name/value pair to the HTTP header. This can be called from anywhere in your Markup::Perl document. param Equivalent to CGI::param. Returns the GET or POST value with the given name. cookie Given a single string argument, returns the value of any cookie by that name, otherwise sets a cookie with the following values from @_: (name, value, expires, path, domain, secure). src(filename) Transforms the content of the given file to allow mixed literal text and executable <perl>...</perl> code, and evals that content.
For the sake of speed and simplicity, Ive left some areas of the code less than bullet-proof. However, if you simply avoid the following bullets, this wont be a problem:
<perl> <perl> print <./perl>; </perl>
including yourself It is possible to include and run Markup::Perl code from other files using the src 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 do file.pl function in such a way, and its left to the programmer to avoid doing this. use utf8 Ive made every effort to write code that is UTF-8 friendly. So much so that you are likely to experience more problems for <B>notB> using UTF-8. Saving your documents as UTF-8 (no BOM) is recommended; other settings may or may not work. Files included via the src function are <B>alwaysB> assumed to be UTF-8.
The author does not claim copyright on any part of this code; unless otherwise licensed, code in this work should be considered Public Domain.
Michael Mathews <firstname.lastname@example.org>, inspired by !WAHa.06x36 <email@example.com>.
|perl v5.20.3||MARKUP::PERL (3)||2006-09-04|