Created
May 13, 2014 00:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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