NAME
Markapl - Markup as Perl
VERSION
This document describes Markapl version 0.03
SYNOPSIS
package MyView;
use Markapl;
tempalte '/a/page.html' => sub {
h1("#title") { "Hi" };
p(".first") { "In the begining, lorem ipsum...." };
p(style => "color: red;") { "But...." };
}
package main;
my $output = MyView->render("/a/page.html");
TUTORIAL
Here's a short guide how to use this module. You can skip this tutorial section if you're already using Template::Declare, since it's exactly the same.
First of all, you need a sole package for defining your tempaltes, let's call it "MyView" in the example. Then you use Markapl
(but not use base), then your view package will be installed many subroutines automatically:
package MyView;
use Markapl;
To define a template, use template
function like this:
tempalte '/page.html' => sub {
h1("#title") { "Hi" };
p(".first") { "In the begining, lorem ipsum...." };
p(style => "color: red;") { "But...." };
}
To render it, call render
function:
my $out = MyView->render("/page.html");
Besides these two functions, Markapl
also exports about another 120 tag functions that are named after HTML tags, for exapmle, h1, h2, h3, div, p, and span. Almost all HTML tags are defined as a function.
In your template, if you say:
h1 { "Hi" };
It'll be rendered as:
<h1>Hi</h1>
The block after h1
is an anonymous sub-routine, and the return value of which will become the content of the h1
tag.
If you want to add attributes to the tag, do it like this:
div(id => "example", class => "lipsum") { "Lorem ipsum" };
Alternatively, you can use CSS selector syntax to quickly defined id and class attribute:
div("#example") { "Lorem ipsum" };
That only works when the attribute list contain excatly one string inside.
A special function outs
need to be used to concatinate strings with inline elements:
p {
outs "Hello, ";
a(href => "/users/gugod") { "gugod" };
}
DESCRIPTION
This is a new try to use Devel::Declare to change the Perl5 language. It learns pretty much everything from Tempalte::Declare, and has similar interface. With only one difference: how element attributes are defined.
In Template::Declare, it goes like:
h1 {
id is "title";
outs "Hi";
};
In here, it is:
h1(id => "title") { "Hi" };
Or a shorthand for "id" attribute:
h1("#title") { "Hi" };
INTERFACE
- template($name, $code);
-
Defines a template.
- render($name)
-
You need to call it as class method like,
MyView->render("/foo.html");
Or
render MyView, "/foo.html";
If you happen to like this style.
Doesn't support tempalte variable yet. Stay tuned.
- outs($str);
-
Should be used in side a template body. It appends
$str
to current output buffer frame.
DEPENDENCIES
Devel::Declare
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-markapl@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Kang-min Liu <gugod@gugod.org>
LICENCE AND COPYRIGHT
Copyright (c) 2008, Kang-min Liu <gugod@gugod.org>
.
This is free software, licensed under:
The MIT (X11) License
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.