File: BuildAll.pm

package info (click to toggle)
libmoox-strictconstructor-perl 0.013-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: perl: 431; makefile: 2; sh: 1
file content (65 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;                     # redundant, but quiets perlcritic
use warnings;
package MooX::StrictConstructor::Role::BuildAll;

our $VERSION = '0.013';

use Moo::Role;

has _constructor_generator => (
    is => 'rw',
    weaken => 1,
);

around buildall_body_for => sub {
    my ($orig, $self, $into, $me, $args, @extra) = @_;

    my $con = $self->_constructor_generator;
    my $fake_BUILD = $con->can('_fake_BUILD');
    my $real_build = ! do {
        no strict 'refs';
        defined &{"${into}::BUILD"} && \&{"${into}::BUILD"} == $fake_BUILD;
    };

    my $code = '';
    if ($real_build) {
        $code .= $self->$orig($into, $me, $args, @extra);
    }
    my $arg = $args =~ /^\$\w+(?:\[[0-9]+\])?$/ ? $args : "($args)[0]";
    $code .= "do {\n" . $con->_cap_call($con->_check_strict($con->all_attribute_specs, $arg)) . "},\n";
    return $code;
};

1;

__END__

=pod

=encoding UTF-8

=for :stopwords George Hartzell

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website
L<https://rt.cpan.org/Public/Dist/Display.html?Name=MooX-StrictConstructor>
or by email to
L<bug-MooX-StrictConstructor@rt.cpan.org|mailto:bug-MooX-StrictConstructor@rt.cpan.org>.

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

George Hartzell <hartzell@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by George Hartzell.

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