6 use Test::More tests => 1;
11 ## meta-attribute example
14 package MyApp::Meta::Attribute::Labeled;
16 extends 'Moose::Meta::Attribute';
21 predicate => 'has_label',
24 package Moose::Meta::Attribute::Custom::Labeled;
25 sub register_implementation { 'MyApp::Meta::Attribute::Labeled' }
27 package MyApp::Website;
31 metaclass => 'Labeled',
34 label => "The site's URL",
47 # iterate over all the attributes in $self
48 my %attributes = %{ $self->meta->get_attribute_map };
49 foreach my $name (sort keys %attributes) {
51 my $attribute = $attributes{$name};
53 # print the label if available
54 if ($attribute->isa('MyApp::Meta::Attribute::Labeled')
55 && $attribute->has_label) {
56 $dump_value .= $attribute->label;
58 # otherwise print the name
63 # print the attribute's value
64 my $reader = $attribute->get_read_method;
65 $dump_value .= ": " . $self->$reader . "\n";
73 my $app = MyApp::Website->new(url => "http://google.com", name => "Google");
74 is($app->dump, q{name: Google
75 The site's URL: http://google.com
76 }, '... got the expected dump value');