File Coverage

blib/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package MooseX::NonMoose::Meta::Role::Constructor;
2              
3 23     23   240604 use Moose::Role 2.0000;
  23         738  
  23         230  
4              
5             # ABSTRACT: constructor method trait for L<MooseX::NonMoose>
6             our $VERSION = '0.27'; # VERSION
7              
8              
9             around can_be_inlined => sub {
10             my $orig = shift;
11             my $self = shift;
12              
13             my $meta = $self->associated_metaclass;
14             my $super_new = $meta->find_method_by_name($self->name);
15             my $super_meta = $super_new->associated_metaclass;
16             if (Moose::Util::find_meta($super_meta)->can('does_role')
17             && Moose::Util::find_meta($super_meta)->does_role('MooseX::NonMoose::Meta::Role::Class')) {
18             return 1;
19             }
20              
21             return $self->$orig(@_);
22             };
23              
24 23     23   150439 no Moose::Role;
  23         49  
  23         141  
25              
26             1;
27              
28             __END__
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             MooseX::NonMoose::Meta::Role::Constructor - constructor method trait for L<MooseX::NonMoose>
37              
38             =head1 VERSION
39              
40             version 0.27
41              
42             =head1 SYNOPSIS
43              
44             package My::Moose;
45             use Moose ();
46             use Moose::Exporter;
47              
48             Moose::Exporter->setup_import_methods;
49             sub init_meta {
50             shift;
51             my %options = @_;
52             Moose->init_meta(%options);
53             Moose::Util::MetaRole::apply_metaclass_roles(
54             for_class => $options{for_class},
55             metaclass_roles => ['MooseX::NonMoose::Meta::Role::Class'],
56             constructor_class_roles =>
57             ['MooseX::NonMoose::Meta::Role::Constructor'],
58             );
59             return Moose::Util::find_meta($options{for_class});
60             }
61              
62             =head1 DESCRIPTION
63              
64             This trait implements inlining of the constructor for classes using the
65             L<MooseX::NonMoose::Meta::Role::Class> metaclass trait; it has no effect unless
66             that trait is also used. See those docs and the docs for L<MooseX::NonMoose>
67             for more information.
68              
69             =head1 AUTHOR
70              
71             Original author: Jesse Luehrs E<lt>doy@tozt.netE<gt>
72              
73             Current maintainer: Graham Ollis E<lt>plicease@cpan.orgE<gt>
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             This software is copyright (c) 2009-2025 by Jesse Luehrs.
78              
79             This is free software; you can redistribute it and/or modify it under
80             the same terms as the Perl 5 programming language system itself.
81              
82             =cut