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

NAME

Inline::Mason - Inline Mason Script

SYNOPSIS

    package MY::Mason;
    use Inline::Mason 'as_subs';
    our @ISA = qw(Inline::Mason);

    print Inline::Mason::generate('HELLO');
    print Inline::Mason::HELLO();
    print HELLO();
    print NIFTY(lang => 'Perl');



    __END__

    __HELLO__
    % my $noun = 'World';
    Hello <% $noun %>!
    How are ya?

    __NIFTY__
    <% $ARGS{lang} %> is nifty!

DESCRIPTION

This module enables you to embed mason scripts in your perl code. Using it is simple, much is shown in the above.

OPTIONS

as_subs

Invoking Inline::Mason with it may let you treat virtual files as subroutines and call them directly.

passive

If it is passed, the module will not spontaneously load mason scripts until you explicitly load them.

FUNCTIONS

load_mason

Create mason scripts in place, and you can pass a list of pairs.

    Inline::Mason::load_mason
    (
     BEATLES
     =>
     'Nothing\'s gonna change my <% $ARGS{what} %>',
     # ... ... ...
     );

    print BEATLES(what => 'world');

load_file

Load an external file manually and explicitly, and the scripts will belong to the caller's package. This is a safer and more robust way when Inline::Mason is used across several files and packages.

    use Inline::Mason qw(passive as_subs);
    Inline::Mason::load_file('external_mason.txt');

EXTERNAL MASON

As is said in the above, load_file serves the purpose. Also, you can specify the files wherein mason scripts reside when you first use the module. All you need to do is pass their names when you use the module, and then Inline::Mason will actively process them.

  use Inline::Mason 'as_subs', [qw(external_mason.txt)];

When duplicated mason script's marker appears, new one overrides the old one.

PER-PACKAGE MASON

Inline mason scripts are specific to packages. It means if you load virtual files within two different package context, files with the same marker will be viewed as different entities.

An small example is illustrated below.

File A.pm

  package A;
  use Inline::Mason qw(as_subs);
  1;
  __END__
  __Mason__
  Hello, World.

File B.pm

  package B;
  use Inline::Mason qw(as_subs);
  require 'A.pm';
  package A;
  print Mason();        # Hello, World.
  package B;
  print Mason();        # Hola, el mundo.
  1;
  __END__
  __Mason__
  Hola, el mundo.

Text::MicroMason methods

You can also call methods provided by Text::MicroMason using Inline::Mason.

  Inline::Mason::execute( $hello );
  Inline::Mason::safe_execute( $hello );
  Inline::Mason::try_execute( $hello );

  $n = Inline::Mason::compile( $nifty );
  $n->(lang => "Perl");

  Inline::Mason::execute_file( 't/external_mason', lang => "Perl" );

SEE ALSO

See Inline::Mason::OO for an object-oriented and extended style of Inline::Mason

This module uses Text::MicroMason as its backend instead of HTML::Mason, because it is much lighter and more accessible for this purpose. Please go to Text::MicroMason for details and its limitations.

CAVEAT

This module is not mature yet, and everything is subject to changes. Use it with your own caution.

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Yung-chung Lin (a.k.a. xern) <xern@cpan.org>

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