Permalink
Browse files

Be more strict about what gets accepted as injectable "code part".

  • Loading branch information...
1 parent 2f551e3 commit 64d82240b6ebf2ecd38b0eead6233d278f5696a2 @phaylon phaylon committed with rafl May 4, 2009
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/MooseX/Declare/Context.pm
@@ -1,12 +1,20 @@
package MooseX::Declare::Context;
use Moose;
+use Moose::Util::TypeConstraints;
use Carp qw/croak/;
use aliased 'Devel::Declare::Context::Simple', 'DDContext';
use namespace::clean -except => 'meta';
+subtype 'MooseX::Declare::BlockCodePart',
+ as 'ArrayRef',
+ where { @$_ > 1 and sub { grep { $_[0] eq $_ } qw( BEGIN END ) } -> ($_->[0]) };
+
+subtype 'MooseX::Declare::CodePart',
+ as 'Str|MooseX::Declare::BlockCodePart';
+
has _dd_context => (
is => 'ro',
isa => DDContext,
@@ -31,21 +39,21 @@ has caller_file => (
has preamble_code_parts => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => 'ArrayRef[MooseX::Declare::CodePart]',
required => 1,
default => sub { [] },
);
has scope_code_parts => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => 'ArrayRef[MooseX::Declare::CodePart]',
required => 1,
default => sub { [] },
);
has cleanup_code_parts => (
is => 'rw',
- isa => 'ArrayRef',
+ isa => 'ArrayRef[MooseX::Declare::CodePart]',
required => 1,
default => sub { [] },
);

0 comments on commit 64d8224

Please sign in to comment.