Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,153 @@
package MooseX::Declare::Context::Namespaced;
# ABSTRACT: Namespaced context
our $VERSION = '0.43';
use Moose::Role;
use Carp qw( croak );
use MooseX::Declare::Util qw( outer_stack_peek );
use namespace::autoclean;
#pod =head1 DESCRIPTION
#pod
#pod This context trait will add namespace functionality to the context.
#pod
#pod =attr namespace
#pod
#pod This will be set when the C<strip_namespace> method is called and the
#pod namespace wasn't anonymous. It will contain the specified namespace, not
#pod the fully qualified one.
#pod
#pod =cut
has namespace => (
is => 'rw',
isa => 'Str',
);
#pod =method strip_namespace
#pod
#pod Maybe[Str] Object->strip_namespace()
#pod
#pod This method is intended to parse the main namespace of a namespaced keyword.
#pod It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store
#pod the result in the L</namespace> attribute if true.
#pod
#pod =cut
sub strip_namespace {
my ($self) = @_;
my $namespace = $self->strip_word;
$self->namespace($namespace)
if defined $namespace and length $namespace;
return $namespace;
}
#pod =method qualify_namespace
#pod
#pod Str Object->qualify_namespace(Str $namespace)
#pod
#pod If the C<$namespace> passed it begins with a C<::>, it will be prefixed with
#pod the outer namespace in the file. If there is no outer namespace, an error
#pod will be thrown.
#pod
#pod =cut
sub qualify_namespace {
my ($self, $namespace) = @_;
# only qualify namespaces starting with ::
return $namespace
unless $namespace =~ /^::/;
# try to find the enclosing package
my $outer = outer_stack_peek($self->caller_file)
or croak "No outer namespace found to apply relative $namespace to";
return $outer . $namespace;
}
#pod =head1 SEE ALSO
#pod
#pod =for :list
#pod * L<MooseX::Declare>
#pod * L<MooseX::Declare::Context>
#pod
#pod =cut
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
MooseX::Declare::Context::Namespaced - Namespaced context
=head1 VERSION
version 0.43
=head1 DESCRIPTION
This context trait will add namespace functionality to the context.
=head1 ATTRIBUTES
=head2 namespace
This will be set when the C<strip_namespace> method is called and the
namespace wasn't anonymous. It will contain the specified namespace, not
the fully qualified one.
=head1 METHODS
=head2 strip_namespace
Maybe[Str] Object->strip_namespace()
This method is intended to parse the main namespace of a namespaced keyword.
It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store
the result in the L</namespace> attribute if true.
=head2 qualify_namespace
Str Object->qualify_namespace(Str $namespace)
If the C<$namespace> passed it begins with a C<::>, it will be prefixed with
the outer namespace in the file. If there is no outer namespace, an error
will be thrown.
=head1 SEE ALSO
=over 4
=item *
L<MooseX::Declare>
=item *
L<MooseX::Declare::Context>
=back
=head1 AUTHOR
Florian Ragwitz <rafl@debian.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2008 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,159 @@
package MooseX::Declare::Context::Parameterized;
# ABSTRACT: context for parsing optionally parameterized statements
our $VERSION = '0.43';
use Moose::Role;
use MooseX::Types::Moose qw/Str HashRef/;
use namespace::autoclean;
#pod =head1 DESCRIPTION
#pod
#pod This context trait will add optional parameterization functionality to the
#pod context.
#pod
#pod =attr parameter_signature
#pod
#pod This will be set when the C<strip_parameter_signature> method is called and it
#pod was able to extract a list of parameterisations.
#pod
#pod =method has_parameter_signature
#pod
#pod Predicate method for the C<parameter_signature> attribute.
#pod
#pod =cut
has parameter_signature => (
is => 'rw',
isa => Str,
predicate => 'has_parameter_signature',
);
#pod =method add_parameter
#pod
#pod Allows storing parameters extracted from C<parameter_signature> to be used
#pod later on.
#pod
#pod =method get_parameters
#pod
#pod Returns all previously added parameters.
#pod
#pod =cut
has parameters => (
traits => ['Hash'],
isa => HashRef,
default => sub { {} },
handles => {
add_parameter => 'set',
get_parameters => 'kv',
},
);
#pod =method strip_parameter_signature
#pod
#pod Maybe[Str] Object->strip_parameter_signature()
#pod
#pod This method is intended to parse the main namespace of a namespaced keyword.
#pod It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store
#pod the result in the L</namespace> attribute if true.
#pod
#pod =cut
sub strip_parameter_signature {
my ($self) = @_;
my $signature = $self->strip_proto;
$self->parameter_signature($signature)
if defined $signature && length $signature;
return $signature;
}
#pod =head1 SEE ALSO
#pod
#pod =for :list
#pod * L<MooseX::Declare>
#pod * L<MooseX::Declare::Context>
#pod
#pod =cut
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
MooseX::Declare::Context::Parameterized - context for parsing optionally parameterized statements
=head1 VERSION
version 0.43
=head1 DESCRIPTION
This context trait will add optional parameterization functionality to the
context.
=head1 ATTRIBUTES
=head2 parameter_signature
This will be set when the C<strip_parameter_signature> method is called and it
was able to extract a list of parameterisations.
=head1 METHODS
=head2 has_parameter_signature
Predicate method for the C<parameter_signature> attribute.
=head2 add_parameter
Allows storing parameters extracted from C<parameter_signature> to be used
later on.
=head2 get_parameters
Returns all previously added parameters.
=head2 strip_parameter_signature
Maybe[Str] Object->strip_parameter_signature()
This method is intended to parse the main namespace of a namespaced keyword.
It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store
the result in the L</namespace> attribute if true.
=head1 SEE ALSO
=over 4
=item *
L<MooseX::Declare>
=item *
L<MooseX::Declare::Context>
=back
=head1 AUTHOR
Florian Ragwitz <rafl@debian.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2008 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,70 @@
package # hide from PAUSE
MooseX::Declare::Context::WithOptions;
our $VERSION = '0.43';
use Moose::Role;
use Carp qw/croak/;
use MooseX::Types::Moose 0.20 qw/HashRef/;
use namespace::autoclean;
has options => (
is => 'rw',
isa => HashRef,
default => sub { {} },
lazy => 1,
);
sub strip_options {
my ($self) = @_;
my %ret;
# Make errors get reported from right place in source file
local $Carp::Internal{'MooseX::Declare'} = 1;
local $Carp::Internal{'Devel::Declare'} = 1;
$self->skipspace;
my $linestr = $self->get_linestr;
while (substr($linestr, $self->offset, 1) !~ /[{;]/) {
my $key = $self->strip_name;
if (!defined $key) {
croak 'expected option name'
if keys %ret;
return; # This is the case when { class => 'foo' } happens
}
croak "unknown option name '$key'"
unless $key =~ /^(extends|with|is)$/;
my $val = $self->strip_name;
if (!defined $val) {
if (defined($val = $self->strip_proto)) {
$val = [split /\s*,\s*/, $val];
}
else {
croak "expected option value after $key";
}
}
$ret{$key} ||= [];
push @{ $ret{$key} }, ref $val ? @{ $val } : $val;
} continue {
$self->skipspace;
$linestr = $self->get_linestr();
}
my $options = { map {
my $key = $_;
$key eq 'is'
? ($key => { map { ($_ => 1) } @{ $ret{$key} } })
: ($key => $ret{$key})
} keys %ret };
$self->options($options);
return $options;
}
1;