6 use Test::More tests => 2;
13 ## meta-attribute example
16 package MyApp::Meta::Attribute::Labeled;
18 extends 'Moose::Meta::Attribute';
23 predicate => 'has_label',
26 package Moose::Meta::Attribute::Custom::Labeled;
27 sub register_implementation { 'MyApp::Meta::Attribute::Labeled' }
29 package MyApp::Website;
33 metaclass => 'Labeled',
36 label => "The site's URL",
49 # iterate over all the attributes in $self
50 my %attributes = %{ $self->meta->get_attribute_map };
51 foreach my $name (sort keys %attributes) {
53 my $attribute = $attributes{$name};
55 # print the label if available
56 if ($attribute->isa('MyApp::Meta::Attribute::Labeled')
57 && $attribute->has_label) {
58 $dump_value .= $attribute->label;
60 # otherwise print the name
65 # print the attribute's value
66 my $reader = $attribute->get_read_method;
67 $dump_value .= ": " . $self->$reader . "\n";
75 my $app = MyApp::Website->new(url => "http://google.com", name => "Google");
76 is($app->dump, q{name: Google
77 The site's URL: http://google.com
78 }, '... got the expected dump value');