X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FClass.pm;h=76f42f3f01d89fd2436456e273932e0c57739620;hb=34a66aa3423e251341c77ba790950eae4fbcfff9;hp=5d5f1afced0eed3331519ae59ece5d4bfe589017;hpb=c0e30cf5d3bbad2b5622975e47c08d8d009e1e97;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 5d5f1af..76f42f3 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -4,8 +4,37 @@ package Moose::Meta::Class; use strict; use warnings; +use Carp 'confess'; + +our $VERSION = '0.02'; + use base 'Class::MOP::Class'; +sub construct_instance { + my ($class, %params) = @_; + my $instance = $params{'__INSTANCE__'} || {}; + foreach my $attr ($class->compute_all_applicable_attributes()) { + my $init_arg = $attr->init_arg(); + # try to fetch the init arg from the %params ... + my $val; + $val = $params{$init_arg} if exists $params{$init_arg}; + # if nothing was in the %params, we can use the + # attribute's default value (if it has one) + $val ||= $attr->default($instance) if $attr->has_default; + if (defined $val) { + if ($attr->has_type_constraint) { + if ($attr->should_coerce && $attr->type_constraint->has_coercion) { + $val = $attr->type_constraint->coercion->coerce($val); + } + (defined($attr->type_constraint->check($val))) + || confess "Attribute (" . $attr->name . ") does not pass the type contraint with '$val'"; + } + } + $instance->{$attr->name} = $val; + } + return $instance; +} + 1; __END__ @@ -14,16 +43,23 @@ __END__ =head1 NAME -Moose::Meta::Class - +Moose::Meta::Class - The Moose metaclass =head1 SYNOPSIS =head1 DESCRIPTION +This is a subclass of L with Moose specific +extensions. + =head1 METHODS =over 4 +=item B + +=item B + =back =head1 BUGS @@ -32,13 +68,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE