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


__END__

=pod

=head1 NAME

Mason::Manual::UpgradingFromMason1 - Summary of differences between Mason 1 and
Mason 2

=head1 DESCRIPTION

Mason 2.x comes ten years after Mason 1.0 (known as L<HTML::Mason>) and twelve
years after the original Mason release.  It has been rearchitected and
reimplemented from the ground up.

That said, the philosophy and core syntax are similar enough that it should
still be recognizable and "feel like Mason" to existing users.

This manual attempts to summarize the differences between Mason 1 and 2, to
help existing users decide if they are interested and, if so, migrate their
projects.

There is currently no automated way to convert a Mason 1 to a Mason 2 site, but
there hopefully will be someday. (Contributions welcome. :))

=head1 ARCHITECTURE

=over

=item *

In Mason 1, each component was an instance of a common Component class. In
Mason 2, each component is its I<own> Moose class, with a class name generated
from the component path.

=item *

The main component body - the content and the inline Perl sections - are placed
into a C<main> method.

=item *

Calling a component (via C<< <& &> >> or C<< $m->comp >> ) entails creating a
new instance of the component class, and calling its C<main> method. Component
call parameters are passed to the constructor and placed in attributes.

=back

=head1 MAJOR FEATURES

=over

=item *

B<Plugins> now utilize Moose roles and are much more powerful and flexible than
in Mason 1. Some features that were (or would have been) in the core of Mason 1
are now in plugins. See L<Mason::Manual::Plugins|Mason::Manual::Plugins>.

=item *

B<Web integration> in Mason 1 was centered around mod_perl and was part of the
core. In Mason 2 all web integration has been split out into a companion web
framework, L<Poet>, which in turn uses L<PSGI> to integrate with any server
backend.  You can also use Mason as the templating layer in popular web
frameworks such as L<Catalyst> and L<Dancer>.  There is no longer anything
web-specific in the Mason core.

=item *

B<Subcomponents> have been eliminated, replaced with class methods.

=item *

B<Error processing/formatting> has been eliminated. Mason now simply throws
fatal errors to the caller.  In a L<Plack|Plack> environment,
L<Plack::Middleware::StackTrace|Plack::Middleware::StackTrace> will catch the
error and format it nicely.

=item *

B<Resolvers> and B<Anonymous components> have been eliminated. Components need
to be in files.  If your components live in another data source, you could use
L<FUSE|http://fuse.sourceforge.net/> or a custom plugin to keep a file
hierarchy up to date with the data source.

=item *

B<Caching> support has been simplified. C<< $m->cache >> simply returns a
L<CHI|CHI> object with an appropriate namespace for the component.

=back

=head1 SYNTAX

=over

=item *

C<< <%once> >> has been replaced with C<< <%class> >>.

=item *

C<< <%cleanup> >> has been eliminated; it was not very useful anyway, since it
was not guaranteed to run after an exception. You can use
L<add_cleanup|Mason::Request/add_cleanup> to add cleanup code for the end of
the request, which is good enough in most cases, or you can add a C<DEMOLISH>
method to the component.

=item *

Single blank lines between blocks are now removed, so you can space blocks out
for readability without generating a ton of newlines.

=item *

Whitespace is required after a %-line and around the expression in a C<< <% %>
>> tag.  This improves readability and leaves open the possibility of
additional syntax.

=item *

C<< <%args> >> and C<< <%shared> >> are gone. Use Moose attributes instead.

=item *

The C<< <%ARGS> >> hash is gone, you can instead use C<< $.args >> or C<<
$self->args >> to get all the parameters passed to a component.

=item *

C<< <%method> >> and C<< <%def> >> have been replaced with just C<< <%method>
>>, which creates a true class method rather than a subcomponent.

=item *

The C<< <%filter> >> tag is now used to define filters, instead of
automatically applying a filter to the current component.

=item *

C<< Components with content >> syntax has been eliminated; use the
L<CompCall|Mason::Filters::Standard/CompCall> filter instead.

=item *

C<< Escape flags >> in substitution tags now utilize
L<filters|Mason::Manual::Filters>.

=back

=head1 MISC PARAMETER CHANGES

=head2 Interp parameters

=over

=item *

C<buffer_preallocate_size>, C<code_cache_max_size> and C<use_object_files> have
been deemed unnecessary and eliminated.

=item *

C<escape_flags> has been eliminated; define filters instead.

=item *

C<data_dir> now defaults to a directory created with
L<tempdir|File::Temp/tempdir>.

=item *

C<preloads> has been eliminated; this code does roughly the same:

    $interp->load($_) for (grep { /some_condition/ } $interp->all_paths);

=back

=head2 Request parameters

=over

=item *

C<autoflush> and C<max_recurse> have been eliminated because they are too
difficult to implement efficiently.

=back

=head2 Compiler parameters

=over

=item *

C<preprocess>, C<postprocess_perl>, and C<postprocess_text> have been
eliminated; similar effects can be achieved with plugins targeting
L<Mason::Compilation|Mason::Compilation>.

=item *

C<default_escape_flags> has been eliminated, but see
L<Mason::Plugin::DefaultFilter|Mason::Plugin::DefaultFilter> for a third-party
substitute.

=back

=head1 MISC METHOD CHANGES

=head2 Interp methods

=over

=item *

C<exec> has been renamed to L<run|Mason::Interp/run>.

=back

=head2 Request methods

=over

=item *

C<cache_self> has been eliminated; use the L<Cache filter|Mason::Plugin::Cache>
instead.

=item *

C<callers>, C<caller> and C<caller_args> have been eliminated; now that
component calls are simply method calls underneath, they are too difficult to
implement efficiently.

=item *

C<call_next> has been replaced with Moose's C<inner>.

=item *

C<call_self> has been eliminated; use L<filters|Mason::Manual::Filters>
instead.

=item *

C<current_comp> has been eliminated. Within a component, use C<< $self >>;
outside a component you can call
L<current_comp_class|Mason::Request/current_comp_class>, which will at least
get you the class.

=item *

C<dhandler_arg> has been renamed to L<path_info|Mason::Request/path_info>.

=item *

C<exec> has been renamed to L<run|Mason::Request/run>.

=item *

C<fetch_comp> has been renamed to L<load|Mason::Request/load>.

=item *

C<subexec> has been replaced with L<visit|Mason::Request/visit> and
L<go|Mason::Request/go>.

=back

=head1 SEE ALSO

L<Mason|Mason>

=head1 AUTHOR

Jonathan Swartz <swartz@pobox.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Jonathan Swartz.

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

=cut