Commit | Line | Data |
c0e30cf5 |
1 | |
2 | package Moose::Meta::Class; |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
a15dff8d |
7 | use Carp 'confess'; |
8 | |
0e3def6b |
9 | our $VERSION = '0.02'; |
bc1e29b5 |
10 | |
c0e30cf5 |
11 | use base 'Class::MOP::Class'; |
12 | |
a15dff8d |
13 | sub construct_instance { |
14 | my ($class, %params) = @_; |
e522431d |
15 | my $instance = $params{'__INSTANCE__'} || {}; |
a15dff8d |
16 | foreach my $attr ($class->compute_all_applicable_attributes()) { |
17 | my $init_arg = $attr->init_arg(); |
18 | # try to fetch the init arg from the %params ... |
19 | my $val; |
20 | $val = $params{$init_arg} if exists $params{$init_arg}; |
21 | # if nothing was in the %params, we can use the |
22 | # attribute's default value (if it has one) |
23 | $val ||= $attr->default($instance) if $attr->has_default; |
24 | if (defined $val && $attr->has_type_constraint) { |
5569c072 |
25 | (defined($attr->type_constraint->($val))) |
26 | || confess "Attribute () does not pass the type contraint with"; |
a15dff8d |
27 | } |
28 | $instance->{$attr->name} = $val; |
29 | } |
30 | return $instance; |
31 | } |
32 | |
c0e30cf5 |
33 | 1; |
34 | |
35 | __END__ |
36 | |
37 | =pod |
38 | |
39 | =head1 NAME |
40 | |
e522431d |
41 | Moose::Meta::Class - The Moose metaclass |
c0e30cf5 |
42 | |
43 | =head1 SYNOPSIS |
44 | |
45 | =head1 DESCRIPTION |
46 | |
e522431d |
47 | This is a subclass of L<Class::MOP::Class> with Moose specific |
48 | extensions. |
49 | |
c0e30cf5 |
50 | =head1 METHODS |
51 | |
52 | =over 4 |
53 | |
a15dff8d |
54 | =item B<construct_instance> |
55 | |
ef1d5f4b |
56 | =item B<mixed_in> |
57 | |
c0e30cf5 |
58 | =back |
59 | |
60 | =head1 BUGS |
61 | |
62 | All complex software has bugs lurking in it, and this module is no |
63 | exception. If you find a bug please either email me, or add the bug |
64 | to cpan-RT. |
65 | |
c0e30cf5 |
66 | =head1 AUTHOR |
67 | |
68 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
69 | |
70 | =head1 COPYRIGHT AND LICENSE |
71 | |
72 | Copyright 2006 by Infinity Interactive, Inc. |
73 | |
74 | L<http://www.iinteractive.com> |
75 | |
76 | This library is free software; you can redistribute it and/or modify |
77 | it under the same terms as Perl itself. |
78 | |
79 | =cut |