line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Declare::Context::Namespaced; |
2
|
|
|
|
|
|
|
# ABSTRACT: Namespaced context |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
9946
|
use Moose::Role; |
|
24
|
|
|
|
|
38
|
|
|
24
|
|
|
|
|
178
|
|
7
|
24
|
|
|
24
|
|
81928
|
use Carp qw( croak ); |
|
24
|
|
|
|
|
41
|
|
|
24
|
|
|
|
|
1396
|
|
8
|
24
|
|
|
24
|
|
108
|
use MooseX::Declare::Util qw( outer_stack_peek ); |
|
24
|
|
|
|
|
30
|
|
|
24
|
|
|
|
|
115
|
|
9
|
24
|
|
|
24
|
|
3264
|
use namespace::autoclean; |
|
24
|
|
|
|
|
36
|
|
|
24
|
|
|
|
|
237
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
12
|
|
|
|
|
|
|
#pod |
13
|
|
|
|
|
|
|
#pod This context trait will add namespace functionality to the context. |
14
|
|
|
|
|
|
|
#pod |
15
|
|
|
|
|
|
|
#pod =attr namespace |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod This will be set when the C<strip_namespace> method is called and the |
18
|
|
|
|
|
|
|
#pod namespace wasn't anonymous. It will contain the specified namespace, not |
19
|
|
|
|
|
|
|
#pod the fully qualified one. |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod =cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has namespace => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#pod =method strip_namespace |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod Maybe[Str] Object->strip_namespace() |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod This method is intended to parse the main namespace of a namespaced keyword. |
34
|
|
|
|
|
|
|
#pod It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store |
35
|
|
|
|
|
|
|
#pod the result in the L</namespace> attribute if true. |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod =cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub strip_namespace { |
40
|
63
|
|
|
63
|
1
|
99
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
63
|
|
|
|
|
319
|
my $namespace = $self->strip_word; |
43
|
|
|
|
|
|
|
|
44
|
63
|
100
|
66
|
|
|
4339
|
$self->namespace($namespace) |
45
|
|
|
|
|
|
|
if defined $namespace and length $namespace; |
46
|
|
|
|
|
|
|
|
47
|
63
|
|
|
|
|
187
|
return $namespace; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#pod =method qualify_namespace |
51
|
|
|
|
|
|
|
#pod |
52
|
|
|
|
|
|
|
#pod Str Object->qualify_namespace(Str $namespace) |
53
|
|
|
|
|
|
|
#pod |
54
|
|
|
|
|
|
|
#pod If the C<$namespace> passed it begins with a C<::>, it will be prefixed with |
55
|
|
|
|
|
|
|
#pod the outer namespace in the file. If there is no outer namespace, an error |
56
|
|
|
|
|
|
|
#pod will be thrown. |
57
|
|
|
|
|
|
|
#pod |
58
|
|
|
|
|
|
|
#pod =cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub qualify_namespace { |
61
|
35
|
|
|
35
|
1
|
63
|
my ($self, $namespace) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# only qualify namespaces starting with :: |
64
|
35
|
100
|
|
|
|
247
|
return $namespace |
65
|
|
|
|
|
|
|
unless $namespace =~ /^::/; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# try to find the enclosing package |
68
|
7
|
50
|
|
|
|
213
|
my $outer = outer_stack_peek($self->caller_file) |
69
|
|
|
|
|
|
|
or croak "No outer namespace found to apply relative $namespace to"; |
70
|
|
|
|
|
|
|
|
71
|
7
|
|
|
|
|
41
|
return $outer . $namespace; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
75
|
|
|
|
|
|
|
#pod |
76
|
|
|
|
|
|
|
#pod =for :list |
77
|
|
|
|
|
|
|
#pod * L<MooseX::Declare> |
78
|
|
|
|
|
|
|
#pod * L<MooseX::Declare::Context> |
79
|
|
|
|
|
|
|
#pod |
80
|
|
|
|
|
|
|
#pod =cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
MooseX::Declare::Context::Namespaced - Namespaced context |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
version 0.43 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This context trait will add namespace functionality to the context. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 namespace |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This will be set when the C<strip_namespace> method is called and the |
107
|
|
|
|
|
|
|
namespace wasn't anonymous. It will contain the specified namespace, not |
108
|
|
|
|
|
|
|
the fully qualified one. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 strip_namespace |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Maybe[Str] Object->strip_namespace() |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This method is intended to parse the main namespace of a namespaced keyword. |
117
|
|
|
|
|
|
|
It will use L<Devel::Declare::Context::Simple>s C<strip_word> method and store |
118
|
|
|
|
|
|
|
the result in the L</namespace> attribute if true. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 qualify_namespace |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Str Object->qualify_namespace(Str $namespace) |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If the C<$namespace> passed it begins with a C<::>, it will be prefixed with |
125
|
|
|
|
|
|
|
the outer namespace in the file. If there is no outer namespace, an error |
126
|
|
|
|
|
|
|
will be thrown. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SEE ALSO |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 4 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<MooseX::Declare> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<MooseX::Declare::Context> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is copyright (c) 2008 by Florian Ragwitz. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
151
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |