| 1 | package Mason::Component::Moose; ## no critic (Moose::RequireMakeImmutable) | ||
| 2 | $Mason::Component::Moose::VERSION = '2.23'; | ||
| 3 | use Moose (); | ||
| 4 | use MooseX::HasDefaults::RW (); | ||
| 5 | use Method::Signatures::Simple (); | ||
| 6 | use Moose::Exporter; | ||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | Moose::Exporter->setup_import_methods( also => ['Moose'] ); | ||
| 10 | |||
| 11 | sub init_meta { | ||
| 12 | my $class = shift; | ||
| 13 | my %params = @_; | ||
| 14 | my $for_class = $params{for_class}; | ||
| 15 | Method::Signatures::Simple->import( into => $for_class ); | ||
| 16 | MooseX::HasDefaults::RW->import( { into => $for_class } ); | ||
| 17 | { | ||
| 18 | no strict 'refs'; | ||
| 19 | *{ $for_class . '::CLASS' } = sub () { $for_class }; # like CLASS.pm | ||
| 20 | *{ $for_class . '::CLASS' } = \$for_class; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | 1; | ||
| 25 | |||
| 26 | __END__ | ||
| 27 | |||
| 28 | =pod | ||
| 29 | |||
| 30 | =head1 NAME | ||
| 31 | |||
| 32 | Mason::Component::Moose - Moose policies and exports for Mason components | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | This module is automatically included in each generated Mason component class, | ||
| 37 | and is equivalent to | ||
| 38 | |||
| 39 | use CLASS; | ||
| 40 | use Moose; | ||
| 41 | use MooseX::HasDefaults::RW; | ||
| 42 | use Method::Signatures::Simple; | ||
| 43 | |||
| 44 | =head1 OVERRIDING | ||
| 45 | |||
| 46 | To override the default behavior, subclass this class and specify it as | ||
| 47 | C<base_component_moose_class> to L<Mason::Interp|Mason::Interp>. | ||
| 48 | |||
| 49 | For example, to use L<MooseX::StrictConstructor> in every component: | ||
| 50 | |||
| 51 | package My::Mason::Component::Moose; | ||
| 52 | use Moose::Exporter; | ||
| 53 | use MooseX::StrictConstructor (); | ||
| 54 | use base qw(Mason::Component::Moose); | ||
| 55 | |||
| 56 | sub init_meta { | ||
| 57 | my $class = shift; | ||
| 58 | $class->SUPER::init_meta(@_); | ||
| 59 | MooseX::StrictConstructor->init_meta(@_); | ||
| 60 | } | ||
| 61 | |||
| 62 | ... | ||
| 63 | |||
| 64 | my $interp = Mason::Interp->new(..., base_component_moose_class => 'My::Mason::Component::Moose'); | ||
| 65 | |||
| 66 | =head1 SEE ALSO | ||
| 67 | |||
| 68 | L<Mason|Mason> | ||
| 69 | |||
| 70 | =head1 AUTHOR | ||
| 71 | |||
| 72 | Jonathan Swartz <swartz@pobox.com> | ||
| 73 | |||
| 74 | =head1 COPYRIGHT AND LICENSE | ||
| 75 | |||
| 76 | This software is copyright (c) 2012 by Jonathan Swartz. | ||
| 77 | |||
| 78 | This is free software; you can redistribute it and/or modify it under | ||
| 79 | the same terms as the Perl 5 programming language system itself. | ||
| 80 | |||
| 81 | =cut |