Skip to content

Instantly share code, notes, and snippets.

@odyniec
Created May 13, 2014 00:09
Show Gist options
  • Save odyniec/1f9eee5785cd8c37eb51 to your computer and use it in GitHub Desktop.
Save odyniec/1f9eee5785cd8c37eb51 to your computer and use it in GitHub Desktop.
An example Perl program that shows how to enumerate all attributes of a Moo object.
#!/usr/bin/env perl
use warnings;
use strict;
{
package Person;
use Moo;
has 'name' => ( is => 'rw' );
has 'age' => ( is => 'rw' );
has 'likes_disco' => ( is => 'rw' );
}
my $bobby = Person->new( name => 'Bobby', age => 42, likes_disco => 1 );
for (keys(%{Moo->_constructor_maker_for(ref $bobby)->all_attribute_specs})) {
print $_ . "\n";
}
# Prints:
# likes_disco
# name
# age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment