MooseX::Declare::Syntax::Keyword::Namespace - Declare outer namespace


MooseX-Declare documentation Contained in the MooseX-Declare distribution.

Index


Code Index:

NAME

Top

MooseX::Declare::Syntax::Keyword::Namespace - Declare outer namespace

SYNOPSIS

Top

  use MooseX::Declare;

  namespace Foo::Bar;

  class ::Baz extends ::Qux with ::Fnording {
      ...
  }

DESCRIPTION

Top

The namespace keyword allows you to declare an outer namespace under which other namespaced constructs can be nested. The SYNOPSIS is effectively the same as

  use MooseX::Declare;

  class Foo::Bar::Baz extends Foo::Bar::Qux with Foo::Bar::Fnording {
      ...
  }

METHODS

Top

parse

  Object->parse(Object $context)

Will skip the declarator, parse the namespace and push the namespace in the file package stack.

CONSUMES

Top

SEE ALSO

Top

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


MooseX-Declare documentation Contained in the MooseX-Declare distribution.

package MooseX::Declare::Syntax::Keyword::Namespace;
BEGIN {
  $MooseX::Declare::Syntax::Keyword::Namespace::AUTHORITY = 'cpan:FLORA';
}
BEGIN {
  $MooseX::Declare::Syntax::Keyword::Namespace::VERSION = '0.34';
}
# ABSTRACT: Declare outer namespace

use Moose;
use Carp qw( confess );

use MooseX::Declare::Util qw( outer_stack_push outer_stack_peek );

use namespace::clean -except => 'meta';


with qw(
    MooseX::Declare::Syntax::KeywordHandling
);


sub parse {
    my ($self, $ctx) = @_;

    confess "Nested namespaces are not supported yet"
        if outer_stack_peek $ctx->caller_file;

    $ctx->skip_declarator;
    my $namespace = $ctx->strip_word
        or confess "Expected a namespace argument to use from here on";

    confess "Relative namespaces are currently not supported"
        if $namespace =~ /^::/;

    $ctx->skipspace;

    my $next_char = $ctx->peek_next_char;
    confess "Expected end of statement after namespace argument"
        unless $next_char eq ';';

    outer_stack_push $ctx->caller_file, $namespace;
}


1;

__END__