Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created April 12, 2013 21:17
Show Gist options
  • Select an option

  • Save tobyink/5375199 to your computer and use it in GitHub Desktop.

Select an option

Save tobyink/5375199 to your computer and use it in GitHub Desktop.
use v5.14;
{
package QueryListExtended;
use Moose;
extends 'Class::MOP::Class';
sub get_all_attributes_names
{
my $self = shift;
my @arrayOfNamesOfAttributes;
my @arrayOfAttributes = $self->get_all_attributes();
foreach my $attribute (@arrayOfAttributes) {
push (@arrayOfNamesOfAttributes, $attribute->name());
}
return @arrayOfNamesOfAttributes;
}
sub call_attribute
{
my $self = shift;
print $_[0];
return $self->{$_[0]};
}
};
use Data::Dumper;
# Global Declarations
my $class = QueryListExtended->create('Foo');
# Attribute & method creation.
$class->add_attribute(bar => (accessor => 'bar'));
$class->add_attribute(ber => (accessor => 'ber'));
$class->add_attribute(bir => (accessor => 'bir'));
$class->add_attribute(beer => (accessor => 'beer'));
# Create an instance of the Foo class with some data
my $object = $class->new_object(bar => 123, ber => 456, bir => 789, beer => "Harvey's");
my @arrayOfAttributes = sort $class->get_all_attributes_names();
my $method_name = $arrayOfAttributes[0];
say $method_name, ": ", $object->$method_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment