mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-02-28 02:07:54 +08:00
Merged Lmo and updated everything that used it
This commit is contained in:
45
lib/Lmo/Meta.pm
Normal file
45
lib/Lmo/Meta.pm
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user