2 package MooseX::Storage::Engine;
17 (shift)->collapse_object;
22 $self->process_attributes;
23 return $self->storage;
26 sub extract_attributes {
28 return $self->object->meta->compute_all_applicable_attributes;
31 sub process_attributes {
33 foreach my $attr ($self->extract_attributes) {
34 next if $attr->name eq '_storage';
35 $self->process_attribute($attr);
39 sub process_attribute {
40 my ($self, $attr) = @_;
41 $self->storage->{$attr->name} = $self->collapse_attribute($attr);
45 'Int' => sub { shift },
46 'Num' => sub { shift },
47 'Str' => sub { shift },
48 'ArrayRef' => sub { shift },
49 'HashRef' => sub { shift },
50 'GlobRef' => sub { confess "FOO" },
51 'CodeRef' => sub { confess "This should use B::Deparse" },
54 $obj || confess("Object Not Defined");
55 ($obj->does('MooseX::Storage::Base'))
56 || confess "Bad object";
62 my ($self, $type_constraint) = @_;
63 return $TYPES{$type_constraint->name} if exists $TYPES{$type_constraint->name};
64 foreach my $type (keys %TYPES) {
66 if $type_constraint->is_subtype_of($type);
70 sub collapse_attribute {
71 my ($self, $attr) = @_;
72 my $value = $attr->get_value($self->object);
73 if (defined $value && $attr->has_type_constraint) {
74 my $type_converter = $self->match_type($attr->type_constraint);
75 (defined $type_converter)
76 || confess "Cannot convert " . $attr->type_constraint->name;
77 $value = $type_converter->($value);