Skip to content

Commit

Permalink
better Mojo::Template examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 11, 2012
1 parent df01b48 commit fcbe89e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.96 2012-05-11
2.96 2012-05-12
- Improved documentation.
- Improved tests.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM.pm
Expand Up @@ -17,7 +17,7 @@ sub AUTOLOAD {

# Method
my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)\:\:(\w+)$/;
croak qq[Undefined subroutine &${package}::$method called]
croak "Undefined subroutine &${package}::$method called"
unless blessed $self && $self->isa(__PACKAGE__);

# Search children
Expand Down
24 changes: 16 additions & 8 deletions lib/Mojo/Template.pm
Expand Up @@ -65,7 +65,7 @@ sub build {
if ($type eq 'text') {

# Quote and fix line ending
$value = quotemeta($value);
$value = quotemeta $value;
$value .= '\n' if $newline;
$lines[-1] .= "\$_M .= \"" . $value . "\";" if length $value;
}
Expand Down Expand Up @@ -368,23 +368,31 @@ Mojo::Template - Perl-ish templates!
# Simple
my $output = $mt->render(<<'EOF');
% use Time::Piece;
<!DOCTYPE html>
<html>
<head><title>Simple</title></head>
<body>Time: <%= localtime(time) %></body>
% my $now = localtime;
<body>Time: <%= $now->hms %></body>
</html>
EOF
say $output;
# More complicated
my $output = $mt->render(<<'EOF', 23, 'foo bar');
%= 5 * 5
% my ($number, $text) = @_;
test 123
foo <% my $i = $number + 2; %>
% for (1 .. 23) {
* some text <%= $i++ %>
% }
%= 5 * 5
<!DOCTYPE html>
<html>
<head><title>Simple</title></head>
<body>
test 123
foo <% my $i = $number + 2; %>
% for (1 .. 23) {
* some text <%= $i++ %>
% }
</body>
</html>
EOF
say $output;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -43,7 +43,7 @@ sub AUTOLOAD {

# Method
my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)\:\:(\w+)$/;
croak qq[Undefined subroutine &${package}::$method called]
croak "Undefined subroutine &${package}::$method called"
unless blessed $self && $self->isa(__PACKAGE__);

# Check for helper
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -42,7 +42,7 @@ sub AUTOLOAD {

# Method
my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)\:\:(\w+)$/;
Carp::croak(qq[Undefined subroutine &${package}::$method called])
Carp::croak("Undefined subroutine &${package}::$method called")
unless Scalar::Util::blessed($self) && $self->isa(__PACKAGE__);

# Call helper
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Route.pm
Expand Up @@ -16,7 +16,7 @@ sub AUTOLOAD {

# Method
my ($package, $method) = our $AUTOLOAD =~ /^([\w:]+)\:\:(\w+)$/;
croak qq[Undefined subroutine &${package}::$method called]
croak "Undefined subroutine &${package}::$method called"
unless blessed $self && $self->isa(__PACKAGE__);

# Call shortcut
Expand Down

0 comments on commit fcbe89e

Please sign in to comment.