Skip to content

Instantly share code, notes, and snippets.

@nperez
Created September 4, 2009 13:44
Show Gist options
  • Save nperez/180886 to your computer and use it in GitHub Desktop.
Save nperez/180886 to your computer and use it in GitHub Desktop.
diff --git a/lib/MooseX/Declare/Syntax/Keyword/Role.pm b/lib/MooseX/Declare/Syntax/Keyword/Role.pm
index 889cf0a..4b7944a 100644
--- a/lib/MooseX/Declare/Syntax/Keyword/Role.pm
+++ b/lib/MooseX/Declare/Syntax/Keyword/Role.pm
@@ -66,7 +66,7 @@ sub add_parameterized_customizations {
my @vars = map {
does_role($_, Placeholder)
? ()
- : [$_->variable_name, $_->label, $_->meta_type_constraint]
+ : [$_->variable_name, $_->label, $_->meta_type_constraint, $_->default_value]
} $sig->named_params;
$ctx->add_preamble_code_parts(
@@ -74,8 +74,16 @@ sub add_parameterized_customizations {
join(',', map { $_->[0] } @vars),
join(' ', map { $_->[1] } @vars),
);
-
- $ctx->add_parameter($_->[1] => { isa => $_->[2] }) for @vars;
+
+ foreach(@vars) {
+ if($_->[3]) {
+ my $default = $_->[3];
+ $ctx->add_parameter($_->[1] => { isa => $_->[2], default => sub { eval $default}});
+ }
+ else {
+ $ctx->add_parameter($_->[1] => { isa => $_->[2] });
+ }
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment