Revision history for Perl extension Moose
-0.30
+0.30 Fri. Nov. 23, 2007
* Moose::Meta::Method::Constructor
-builder related bug in inlined constructor. (groditi)
with work correctly.
- added tests for this
+ * Moose::Cookbook
+ - adding the link to Recipie 11 (written by Sartak)
+ - adding test for SYNOPSIS code
+
* t/
- New tests for builder bug. Upon instantiation, if an
attribute had a builder, no value and was not lazy the
t/000_recipes/005_recipe.t
t/000_recipes/006_recipe.t
t/000_recipes/007_recipe.t
+t/000_recipes/011_recipe.t
t/010_basics/001_basic_class_setup.t
t/010_basics/002_require_superclasses.t
t/010_basics/003_super_and_override.t
# prereqs
requires 'Scalar::Util' => $win32 ? '1.17' : '1.18';
requires 'Carp';
-requires 'Class::MOP' => '0.43';
-requires 'Sub::Name' => '0.02';
+requires 'Class::MOP' => '0.46';
+requires 'Sub::Name' => '0.02';
requires 'Sub::Exporter' => '0.972';
requires 'B';
# things the tests need
-build_requires 'Test::More' => '0.62';
+build_requires 'Test::More' => '0.62';
build_requires 'Test::Exception' => '0.21';
build_requires 'Test::LongString';
use Sub::Exporter;
-use Class::MOP 0.43;
+use Class::MOP 0.46;
use Moose::Meta::Class;
use Moose::Meta::TypeConstraint;
# override a specific class
$meta = $class->meta();
( blessed($meta) && $meta->isa('Moose::Meta::Class') )
- || confess
-"You already have a &meta function, but it does not return a Moose::Meta::Class";
+ || confess "You already have a &meta function, but it does not return a Moose::Meta::Class";
}
else {
# NOTE:
$class->meta->add_augment_method_modifier( $name => $method );
};
},
-
- # NOTE:
- # this is experimental, but I am not
- # happy with it. If you want to try
- # it, you will have to uncomment it
- # yourself.
- # There is a really good chance that
- # this will be deprecated, dont get
- # too attached
- # self => sub {
- # return subname 'Moose::self' => sub {};
- # },
- # method => sub {
- # my $class = $CALLER;
- # return subname 'Moose::method' => sub {
- # my ($name, $method) = @_;
- # $class->meta->add_method($name, sub {
- # my $self = shift;
- # no strict 'refs';
- # no warnings 'redefine';
- # local *{$class->meta->name . '::self'} = sub { $self };
- # $method->(@_);
- # });
- # };
- # },
-
confess => sub {
return \&Carp::confess;
},
=item L<Moose::Cookbook::Recipe7> - The augment/inner example
+=item L<Moose::Cookbook::Recipe11> - The meta-attribute example
+
=back
=head1 SEE ALSO
+
+=pod
+
=head1 NAME
Moose::Cookbook::Recipe11 - The meta-attribute example
=cut
-1;
-
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 3;
use Test::Exception;
BEGIN {
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More no_plan => 1;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+## meta-attribute example
+{
+
+ package MyApp::Meta::Attribute::Labeled;
+ use Moose;
+ extends 'Moose::Meta::Attribute';
+
+ has label => (
+ is => 'rw',
+ isa => 'Str',
+ predicate => 'has_label',
+ );
+
+ package Moose::Meta::Attribute::Custom::Labeled;
+ sub register_implementation { 'MyApp::Meta::Attribute::Labeled' }
+
+ package MyApp::Website;
+ use Moose;
+
+ has url => (
+ metaclass => 'Labeled',
+ isa => 'Str',
+ is => 'rw',
+ label => "The site's URL",
+ );
+
+ has name => (
+ is => 'rw',
+ isa => 'Str',
+ );
+
+ sub dump {
+ my $self = shift;
+
+ my $dump_value = '';
+
+ # iterate over all the attributes in $self
+ my %attributes = %{ $self->meta->get_attribute_map };
+ while (my ($name, $attribute) = each %attributes) {
+
+ # print the label if available
+ if ($attribute->isa('MyApp::Meta::Attribute::Labeled')
+ && $attribute->has_label) {
+ $dump_value .= $attribute->label;
+ }
+ # otherwise print the name
+ else {
+ $dump_value .= $name;
+ }
+
+ # print the attribute's value
+ my $reader = $attribute->get_read_method;
+ $dump_value .= ": " . $self->$reader . "\n";
+ }
+
+ return $dump_value;
+ }
+
+}
+
+my $app = MyApp::Website->new(url => "http://google.com", name => "Google");
+is($app->dump, q{The site's URL: http://google.com
+name: Google
+}, '... got the expected dump value');
+
+