line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Declare::Context::Namespaced; |
2
|
|
|
|
|
|
|
# ABSTRACT: Namespaced context |
3
|
|
|
|
|
|
|
$MooseX::Declare::Context::Namespaced::VERSION = '0.39'; |
4
|
24
|
|
|
24
|
|
17464
|
use Moose::Role; |
|
24
|
|
|
|
|
61
|
|
|
24
|
|
|
|
|
248
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
189788
|
use Carp qw( croak ); |
|
24
|
|
|
|
|
63
|
|
|
24
|
|
|
|
|
1638
|
|
7
|
24
|
|
|
24
|
|
158
|
use MooseX::Declare::Util qw( outer_stack_peek ); |
|
24
|
|
|
|
|
57
|
|
|
24
|
|
|
|
|
183
|
|
8
|
|
|
|
|
|
|
|
9
|
24
|
|
|
24
|
|
5391
|
use namespace::clean -except => 'meta'; |
|
24
|
|
|
|
|
53
|
|
|
24
|
|
|
|
|
351
|
|
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
|
145
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
63
|
|
|
|
|
428
|
my $namespace = $self->strip_word; |
43
|
|
|
|
|
|
|
|
44
|
63
|
100
|
66
|
|
|
6005
|
$self->namespace($namespace) |
45
|
|
|
|
|
|
|
if defined $namespace and length $namespace; |
46
|
|
|
|
|
|
|
|
47
|
63
|
|
|
|
|
236
|
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
|
87
|
my ($self, $namespace) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# only qualify namespaces starting with :: |
64
|
35
|
100
|
|
|
|
249
|
return $namespace |
65
|
|
|
|
|
|
|
unless $namespace =~ /^::/; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# try to find the enclosing package |
68
|
7
|
50
|
|
|
|
309
|
my $outer = outer_stack_peek($self->caller_file) |
69
|
|
|
|
|
|
|
or croak "No outer namespace found to apply relative $namespace to"; |
70
|
|
|
|
|
|
|
|
71
|
7
|
|
|
|
|
49
|
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.39 |
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 |