Merged Lmo and updated everything that used it

This commit is contained in:
Brian Fraser fraserb@gmail.com
2013-02-01 13:29:48 -03:00
parent 25e62aa305
commit d816c6497e
38 changed files with 5815 additions and 3772 deletions

45
lib/Lmo/Meta.pm Normal file
View File

@@ -0,0 +1,45 @@
{
package Lmo::Meta;
use strict;
use warnings qw( FATAL all );
my %metadata_for;
sub new {
my $class = shift;
return bless { @_ }, $class
}
sub metadata_for {
my $self = shift;
my ($class) = @_;
return $metadata_for{$class} ||= {};
}
sub class { shift->{class} }
sub attributes {
my $self = shift;
return keys %{$self->metadata_for($self->class)}
}
sub attributes_for_new {
my $self = shift;
my @attributes;
my $class_metadata = $self->metadata_for($self->class);
while ( my ($attr, $meta) = each %$class_metadata ) {
if ( exists $meta->{init_arg} ) {
push @attributes, $meta->{init_arg}
if defined $meta->{init_arg};
}
else {
push @attributes, $attr;
}
}
return @attributes;
}
1;
}