1 package MooseX::Declare::Context::Namespaced;
6 use MooseX::Declare::Util qw( outer_stack_peek );
8 use namespace::clean -except => 'meta';
18 my $namespace = $self->strip_word;
20 $self->namespace($namespace)
21 if defined $namespace and length $namespace;
26 sub qualify_namespace {
27 my ($self, $namespace) = @_;
29 # only qualify namespaces starting with ::
31 unless $namespace =~ /^::/;
33 # try to find the enclosing package
34 my $outer = outer_stack_peek($self->caller_file)
35 or croak "No outer namespace found to apply relative $namespace to";
37 return $outer . $namespace;
46 MooseX::Declare::Context::Namespaced - Namespaced context
50 This context trait will add namespace functionality to the context.
56 This will be set when the C<strip_namespace> method is called and the
57 namespace wasn't anonymous. It will contain the specified namespace, not
58 the fully qualified one.
62 =head2 strip_namespace
64 Maybe[Str] Object->strip_namespace()
66 This method is intended to parse the main namespace of a namespaced keyword.
67 It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store
68 the result in the L</namespace> attribute if true.
70 =head2 qualify_namespace
72 Str Object->qualify_namespace(Str $namespace)
74 If the C<$namespace> passed it begins with a C<::>, it will be prefixed with
75 the outer namespace in the file. If there is no outer namespace, an error
82 =item * L<MooseX::Declare>
84 =item * L<MooseX::Declare::Context>
88 =head1 AUTHOR, COPYRIGHT & LICENSE
90 See L<MooseX::Declare>