The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Доброго всем

Mojolicious::Plugin::RenderCGI

¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !

VERSION

0.02

NAME

Mojolicious::Plugin::RenderCGI - Rendering template with Perl code and CGI.pm funcs/subs for tags emits.

SYNOPSIS

  $app->plugin('RenderCGI');
  
  # Set as default handler
  $app->renderer->default_handler('cgi.pl');
  # or same
  $app->defaults(handler=>'cgi.pl');
 
  # Render without setting as default handler
  $c->render(handler => 'cgi.pl');
  

Template

Template is a Perl code that generate content as list of statements. Similar to do BLOCK. Template file name like "templates/foo/bar.html.cgi.pl"

  # $c and $self already are controller
  # $cgi is a CGI object (OO-style)
  
  $c->layout('default', handler=>'ep',);# set handler 'ep' for all includes !!!
  my $foo = $c->stash('foo')
    or die "Where is your FOO?";
  
  #=======================================
  #======= content comma list! ===========
  #=======================================
  
  h1({}, "Welcome"),
  
  $c->include('foo', handler=>'cgi.pl'),# change handler against layout
  $c->include('bar'); # handler still "cgi.pl" unless template "foo" (and its includes) didn`t changes it
  
  <<END_HTML,
  <!-- comment -->
  END_HTML
  
  $self->app->log->info("Template has done")
    && undef,

There are NO Mojolicious helpers without OO-style: $c-> OR $self-> prefix.

REMEMBER! Escapes untrusted data. No auto escapes!

  div({}, esc(...UNTRUSTED DATA...)),

esc is a shortcut for &CGI::escapeHTML.

OPTIONS

name ( string )

  # Mojolicious::Lite
  plugin RenderCGI => {name => 'pl'};

Handler name, defaults to 'cgi.pl'.

import ( string (space delims) | arrayref )

What subs do you want from CGI.pm import

  $app->plugin('RenderCGI', import=>':html -any');
  # or 
  $app->plugin('RenderCGI', import=>[qw(:html -any)]);

See at perldoc CGI.pm section "USING THE FUNCTION-ORIENTED INTERFACE". Default is ':html :form' (string) same as [qw(:html :form)] (arrayref).

  import=>[], # none import, CGI OO-style only

exception ( string | hashref )

To show fatal errors (not found, compile and runtime errors) as content of there template you must set string template.

To show fatals as standard Mojolicious 'exception.<mode>.html.ep' page - set hashref like {'handler'=>'ep', 'layout' => undef,}.

Overwise fatals are skips (empty string whole template).

By default set to hashref {'handler'=>'ep', 'layout' => undef,}.

  exception => 'template', 

Methods, subs, helpers...

Implements register method only. Register new renderer handler 'cgi'. No new helpers.

SEE ALSO

CGI

CGI::HTML::Functions

Mojolicious::Plugin::TagHelpers

HTML::Tiny

AUTHOR

Михаил Че (Mikhail Che), <mche[-at-]cpan.org>

BUGS / CONTRIBUTING

Please report any bugs or feature requests at https://github.com/mche/Mojolicious-Plugin-RenderCGI/issues. Pull requests also welcome.

COPYRIGHT

Copyright 2016 Mikhail Che.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.