| 1 | package Mason; | ||
| 2 | $Mason::VERSION = '2.23'; | ||
| 3 | 22 | ▶ | use Mason::Interp; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 4 | use Mason::PluginManager; | ||
| 5 | use Mason::Util qw(can_load uniq); | ||
| 6 | use Method::Signatures::Simple; | ||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | method new ($class: %params) { | ||
| 11 | |||
| 12 | # Extract plugins and base_interp_class | ||
| 13 | # | ||
| 14 | my $plugin_specs = delete( $params{plugins} ) || []; | ||
| 15 | my $base_interp_class = delete( $params{base_interp_class} ) | ||
| 16 | || $class->default_base_interp_class; | ||
| 17 | |||
| 18 | # Process plugins and determine real interp_class | ||
| 19 | # | ||
| 20 | my @plugins = Mason::PluginManager->process_top_plugin_specs($plugin_specs); | ||
| 21 | my $interp_class = | ||
| 22 | Mason::PluginManager->apply_plugins_to_class( $base_interp_class, 'Interp', \@plugins ); | ||
| 23 | |||
| 24 | # Create and return interp | ||
| 25 | # | ||
| 26 | die "cannot pass mason_root_class directly" | ||
| 27 | if exists( $params{mason_root_class} ); | ||
| 28 | return $interp_class->new( | ||
| 29 | mason_root_class => $class, | ||
| 30 | plugins => \@plugins, | ||
| 31 | %params | ||
| 32 | ); | ||
| 33 | } | ||
| 34 | |||
| 35 | method default_base_interp_class ($class:) { | ||
| 36 | my @candidates = | ||
| 37 | map { join( '::', $_, 'Interp' ) } ( uniq( $class, 'Mason' ) ); | ||
| 38 | my ($base_class) = grep { can_load($_) } @candidates | ||
| 39 | or die sprintf( "cannot load %s for interp", join( ', ', @candidates ) ); | ||
| 40 | return $base_class; | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ | ||
| 46 | |||
| 47 | =pod | ||
| 48 | |||
| 49 | =head1 NAME | ||
| 50 | |||
| 51 | Mason - Powerful, high-performance templating for the web and beyond | ||
| 52 | |||
| 53 | =head1 SYNOPSIS | ||
| 54 | |||
| 55 | foo.mc: | ||
| 56 | % my $name = "Mason"; | ||
| 57 | Hello world! Welcome to <% $name %>. | ||
| 58 | |||
| 59 | #!/usr/local/bin/perl | ||
| 60 | use Mason; | ||
| 61 | my $mason = Mason->new(comp_root => '...'); | ||
| 62 | print $mason->run('/foo')->output; | ||
| 63 | |||
| 64 | =head1 DESCRIPTION | ||
| 65 | |||
| 66 | Mason is a powerful Perl-based templating system, designed to generate dynamic | ||
| 67 | content of all kinds. | ||
| 68 | |||
| 69 | Unlike many templating systems, Mason does not attempt to invent an alternate, | ||
| 70 | "easier" syntax for templates. It provides a set of syntax and features | ||
| 71 | specific to template creation, but underneath it is still clearly and proudly | ||
| 72 | recognizable as Perl. | ||
| 73 | |||
| 74 | Mason is most often used for generating web pages. It has a companion web | ||
| 75 | framework, L<Poet|Poet>, designed to take maximum advantage of its routing and | ||
| 76 | content generation features. It can also be used as the templating layer for | ||
| 77 | web frameworks such as L<Catalyst|Catalyst::View::Mason2> and | ||
| 78 | L<Dancer|Dancer::Template::Mason2>. | ||
| 79 | |||
| 80 | All documentation is indexed at L<Mason::Manual>. | ||
| 81 | |||
| 82 | The previous major version of Mason (1.x) is available under the name | ||
| 83 | L<HTML::Mason>. | ||
| 84 | |||
| 85 | =head1 SUPPORT | ||
| 86 | |||
| 87 | The mailing list is C<mason-users@lists.sourceforge.net>. You must be | ||
| 88 | subscribed to send a message. To subscribe, visit | ||
| 89 | L<https://lists.sourceforge.net/lists/listinfo/mason-users>. | ||
| 90 | |||
| 91 | You can also visit us at C<#mason> on L<irc://irc.perl.org/#mason>. | ||
| 92 | |||
| 93 | Bugs and feature requests will be tracked at RT: | ||
| 94 | |||
| 95 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason | ||
| 96 | bug-mason@rt.cpan.org | ||
| 97 | |||
| 98 | The latest source code can be browsed and fetched at: | ||
| 99 | |||
| 100 | http://github.com/jonswar/perl-mason | ||
| 101 | git clone git://github.com/jonswar/perl-mason.git | ||
| 102 | |||
| 103 | The official Mason website is L<http://www.masonhq.com/>, however it contains | ||
| 104 | mostly information about L<Mason 1|HTML::Mason>. We're not sure what the future | ||
| 105 | of the website will be wrt Mason 2. | ||
| 106 | |||
| 107 | =head1 ACKNOWLEDGEMENTS | ||
| 108 | |||
| 109 | Thanks to Stevan Little and the L<Moose> team for the awesomeness of Moose, | ||
| 110 | which motivated me to create a second version of Mason years after I thought I | ||
| 111 | was done. | ||
| 112 | |||
| 113 | Thanks to Tatsuhiko Miyagawa and the L<PSGI/Plack|http://plackperl.org/> team, | ||
| 114 | who freed me from ever worrying about server backends again. | ||
| 115 | |||
| 116 | =head1 SEE ALSO | ||
| 117 | |||
| 118 | L<HTML::Mason> | ||
| 119 | |||
| 120 | =head1 AUTHOR | ||
| 121 | |||
| 122 | Jonathan Swartz <swartz@pobox.com> | ||
| 123 | |||
| 124 | =head1 COPYRIGHT AND LICENSE | ||
| 125 | |||
| 126 | This software is copyright (c) 2012 by Jonathan Swartz. | ||
| 127 | |||
| 128 | This is free software; you can redistribute it and/or modify it under | ||
| 129 | the same terms as the Perl 5 programming language system itself. | ||
| 130 | |||
| 131 | =cut | ||