From: gfx Date: Fri, 9 Oct 2009 05:05:45 +0000 (+0900) Subject: Import a moose cookbook recipe X-Git-Tag: 0.37_05~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef5db57684f356cb09a5e5e8d024d553a292d5d0;p=gitmo%2FMouse.git Import a moose cookbook recipe --- diff --git a/t/000_recipes/moose_cookbook_meta_recipe2.t b/t/000_recipes/moose_cookbook_meta_recipe2.t new file mode 100644 index 0000000..d6a5322 --- /dev/null +++ b/t/000_recipes/moose_cookbook_meta_recipe2.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More 'no_plan'; +use Test::Exception; +$| = 1; + + + +# =begin testing SETUP +{ + + package MyApp::Meta::Attribute::Labeled; + use Mouse; + extends 'Mouse::Meta::Attribute'; + + has label => ( + is => 'rw', + isa => 'Str', + predicate => 'has_label', + ); + + package Mouse::Meta::Attribute::Custom::Labeled; + sub register_implementation {'MyApp::Meta::Attribute::Labeled'} + + package MyApp::Website; + use Mouse; + + has url => ( + metaclass => 'Labeled', + is => 'rw', + isa => 'Str', + label => "The site's URL", + ); + + has name => ( + is => 'rw', + isa => 'Str', + ); + + sub dump { + my $self = shift; + + my $dump = ''; + + for my $name ( sort $self->meta->get_attribute_list ) { + my $attribute = $self->meta->get_attribute($name); + + if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') + && $attribute->has_label ) { + $dump .= $attribute->label; + } + else { + $dump .= $name; + } + + my $reader = $attribute->get_read_method; + $dump .= ": " . $self->$reader . "\n"; + } + + return $dump; + } + + package main; + + my $app = MyApp::Website->new( url => "http://google.com", name => "Google" ); +} + + + +# =begin testing +{ +my $app = MyApp::Website->new( url => "http://google.com", name => "Google" ); +is( + $app->dump, q{name: Google +The site's URL: http://google.com +}, '... got the expected dump value' +); +} + + + + +1;