stupid-monkey
[gitmo/Moose.git] / lib / Moose / Meta / Class.pm
CommitLineData
c0e30cf5 1
2package Moose::Meta::Class;
3
4use strict;
5use warnings;
6
a15dff8d 7use Carp 'confess';
8
bc1e29b5 9our $VERSION = '0.01';
10
c0e30cf5 11use base 'Class::MOP::Class';
12
a15dff8d 13sub construct_instance {
14 my ($class, %params) = @_;
15 my $instance = {};
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) {
25 (defined $attr->type_constraint->($val))
26 || confess "Attribute (" . $attr->name . ") does not pass the type contraint";
27 }
28 $instance->{$attr->name} = $val;
29 }
30 return $instance;
31}
32
c0e30cf5 331;
34
35__END__
36
37=pod
38
39=head1 NAME
40
41Moose::Meta::Class -
42
43=head1 SYNOPSIS
44
45=head1 DESCRIPTION
46
47=head1 METHODS
48
49=over 4
50
a15dff8d 51=item B<construct_instance>
52
c0e30cf5 53=back
54
55=head1 BUGS
56
57All complex software has bugs lurking in it, and this module is no
58exception. If you find a bug please either email me, or add the bug
59to cpan-RT.
60
61=head1 CODE COVERAGE
62
63I use L<Devel::Cover> to test the code coverage of my tests, below is the
64L<Devel::Cover> report on this module's test suite.
65
66=head1 ACKNOWLEDGEMENTS
67
68=head1 AUTHOR
69
70Stevan Little E<lt>stevan@iinteractive.comE<gt>
71
72=head1 COPYRIGHT AND LICENSE
73
74Copyright 2006 by Infinity Interactive, Inc.
75
76L<http://www.iinteractive.com>
77
78This library is free software; you can redistribute it and/or modify
79it under the same terms as Perl itself.
80
81=cut