From 2028eda91a5cdd2600581ed96beeb00f6788e088 Mon Sep 17 00:00:00 2001
From: Toby Inkster <tobyink@cpan.org>
Date: Fri, 18 Nov 2011 13:53:18 +0000
Subject: [PATCH] Allow extra options.

---
 t/extra_options.t |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 t/extra_options.t

diff --git a/t/extra_options.t b/t/extra_options.t
new file mode 100644
index 0000000..5370d21
--- /dev/null
+++ b/t/extra_options.t
@@ -0,0 +1,61 @@
+use MooseX::Declare;
+use Test::More tests => 5;
+
+{
+	package Local::Declare::Syntax::HavingApplication;
+	use Moose::Role;
+	
+	sub add_having_option_customizations
+	{
+		my ($self, $ctx, $package, $attribs) = @_;
+		my @code_parts;
+		push @code_parts, sprintf(
+			"has [%s] => (is => q/rw/, isa => q/Str/)\n",
+			join ', ',
+				map { "q/$_/" }
+				@{ ref $attribs ? $attribs : [$attribs] }
+			);
+		$ctx->add_scope_code_parts(@code_parts);
+		return 1;
+	}
+}
+
+BEGIN {
+	use Moose::Util qw/apply_all_roles/;
+	apply_all_roles('MooseX::Declare::Syntax::Keyword::Class',
+		'Local::Declare::Syntax::HavingApplication');
+	
+	MooseX::Declare::Context::WithOptions->meta->add_around_method_modifier(
+		allowed_option_names => sub
+			{
+				my ($orig, $self, $x) = @_;
+				if ($x)
+				{
+					push @$x, 'having';
+					return $self->$orig($x);
+				}
+				else
+				{
+					$x = $self->$orig();
+					push @$x, 'having';
+					return $x;
+				}
+			}
+		);
+}
+
+class Local::MyClass
+	having foo
+	having bar
+{
+	has baz => (is => 'rw', isa => 'Str');
+}
+
+can_ok('Local::MyClass', 'new');
+
+my $obj = Local::MyClass->new;
+can_ok($obj, 'foo');
+can_ok($obj, 'baz');
+can_ok($obj, 'bar');
+ok(!$obj->can('bat'), "Local::MyClass->can't('bat')");
+
-- 
1.6.4.4

