[svn-upgrade] Integrating new upstream version, libany-moose-perl (0.11)
Jonathan Yu
14 years ago
0 | 0.11 Sun 19 Dec 2009 | |
1 | * Support "use Any::Moose '::Util::TypeConstraints'" (gfx) | |
2 | * Support "no Any::Moose '::Util::TypeConstraints'" (gfx) | |
3 | * $@ related fixes (gfx) | |
4 | * Documentation and other minor improvements (gfx) | |
5 | * Any::Moose should now work when you have Moose but not Mouse. Still need to | |
6 | work out how to encode this in the installation system (Sartak) | |
7 | ||
0 | 8 | 0.10 Fri 19 Jun 2009 |
1 | 9 | * Fix META.yml |
2 | 10 |
16 | 16 | t/005-is_class_loaded-mouse.t |
17 | 17 | t/010-use_mouse_roles.t |
18 | 18 | t/011-use_moose_roles.t |
19 | t/012-use_moose_util.t | |
20 | t/012-use_mouse_util.t | |
19 | 21 | t/020-strict.t |
20 | t/100-canonicalize-fragments.t⏎ | |
22 | t/100-canonicalize-fragments.t | |
23 | t/101-localize-errvar.t | |
24 | t/release-pod-coverage.t | |
25 | t/release-pod-syntax.t⏎ |
4 | 4 | - 'Florian Ragwitz <rafl@debian.org>' |
5 | 5 | - 'Stevan Little <stevan@iinteractive.com>' |
6 | 6 | - 'Tokuhiro Matsuno <tokuhirom@gmail.com>' |
7 | generated_by: 'Dist::Zilla::Plugin::MetaYAML version 1.091480' | |
7 | - 'Goro Fuji <gfuji@cpan.org>' | |
8 | generated_by: 'Dist::Zilla version 1.093400' | |
8 | 9 | license: perl |
9 | 10 | meta-spec: |
10 | 11 | url: http://module-build.sourceforge.net/META-spec-v1.4.html |
11 | 12 | version: 1.4 |
12 | 13 | name: Any-Moose |
13 | 14 | requires: |
14 | Mouse: 0.21 | |
15 | version: 0.10 | |
15 | Mouse: 0.40 | |
16 | perl: 5.006_002 | |
17 | version: 0.11 |
0 | 0 | |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | ||
4 | BEGIN { require 5.006_002; } | |
3 | 5 | |
4 | 6 | use ExtUtils::MakeMaker; |
5 | 7 | |
6 | 8 | WriteMakefile( |
7 | 9 | DISTNAME => 'Any-Moose', |
8 | 10 | NAME => 'Any::Moose', |
9 | AUTHOR => 'Shawn\ M\ Moore\ \<sartak\@bestpractical\.com\>\,\ Florian\ Ragwitz\ \<rafl\@debian\.org\>\,\ Stevan\ Little\ \<stevan\@iinteractive\.com\>\,\ Tokuhiro\ Matsuno\ \<tokuhirom\@gmail\.com\>', | |
10 | ABSTRACT => 'use\ Moose\ or\ Mouse\ modules', | |
11 | VERSION => '0.10', | |
11 | AUTHOR => "Shawn\ M\ Moore\ \<sartak\@bestpractical\.com\>\,\ Florian\ Ragwitz\ \<rafl\@debian\.org\>\,\ Stevan\ Little\ \<stevan\@iinteractive\.com\>\,\ Tokuhiro\ Matsuno\ \<tokuhirom\@gmail\.com\>\,\ Goro\ Fuji\ \<gfuji\@cpan\.org\>", | |
12 | ABSTRACT => "use\ Moose\ or\ Mouse\ modules", | |
13 | VERSION => '0.11', | |
12 | 14 | EXE_FILES => [ qw() ], |
13 | (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()), | |
15 | (eval { ExtUtils::MakeMaker->VERSION(6.31) } ? (LICENSE => 'perl') : ()), | |
14 | 16 | PREREQ_PM => { |
15 | "Mouse" => '0.21', | |
17 | "Mouse" => '0.40', | |
16 | 18 | }, |
19 | test => {TESTS => 't/*.t'} | |
17 | 20 | ); |
21 |
0 | 0 | |
1 | 1 | |
2 | 2 | This archive contains the distribution Any-Moose, version |
3 | 0.10: | |
3 | 0.11: | |
4 | 4 | |
5 | 5 | use Moose or Mouse modules |
6 | 6 |
0 | 0 | name = Any-Moose |
1 | version = 0.10 | |
1 | version = 0.11 | |
2 | 2 | author = Shawn M Moore <sartak@bestpractical.com> |
3 | 3 | author = Florian Ragwitz <rafl@debian.org> |
4 | 4 | author = Stevan Little <stevan@iinteractive.com> |
5 | 5 | author = Tokuhiro Matsuno <tokuhirom@gmail.com> |
6 | author = Goro Fuji <gfuji@cpan.org> | |
6 | 7 | license = Perl_5 |
7 | 8 | copyright_holder = Best Practical Solutions |
8 | 9 | |
13 | 14 | [PodWeaver] |
14 | 15 | |
15 | 16 | [Prereq] |
16 | Mouse = 0.21 | |
17 | ||
17 | Mouse = 0.40 | |
18 | perl = 5.006_002 |
0 | 0 | package Any::Moose; |
1 | our $VERSION = '0.10'; | |
2 | ||
1 | our $VERSION = '0.11'; | |
3 | 2 | # ABSTRACT: use Moose or Mouse modules |
4 | 3 | |
4 | use 5.006_002; | |
5 | 5 | use strict; |
6 | 6 | use warnings; |
7 | ||
8 | use Carp (); | |
7 | 9 | |
8 | 10 | our $PREFERRED = $ENV{'ANY_MOOSE'}; |
9 | 11 | |
11 | 13 | my $self = shift; |
12 | 14 | my $pkg = caller; |
13 | 15 | |
14 | # Any::Moose gives you strict and warnings (but only the first time, in case | |
15 | # you do something like: use Any::Moose; no strict 'refs') | |
16 | if (!defined(_backer_of($pkg))) { | |
17 | strict->import; | |
18 | warnings->import; | |
19 | } | |
16 | # Any::Moose gives you strict and warnings | |
17 | strict->import; | |
18 | warnings->import; | |
20 | 19 | |
21 | 20 | # first options are for Mo*se |
22 | 21 | unshift @_, 'Moose' if !@_ || ref($_[0]); |
39 | 38 | } |
40 | 39 | |
41 | 40 | sub unimport { |
42 | my $self = shift; | |
43 | my $pkg = caller; | |
44 | ||
45 | my $backer = _backer_of($pkg); | |
46 | ||
47 | eval "package $pkg;\n" | |
48 | . '$backer->unimport(@_);'; | |
41 | my $sel = shift; | |
42 | my $pkg = caller; | |
43 | my $module; | |
44 | ||
45 | if(@_){ | |
46 | $module = any_moose(shift, $pkg); | |
47 | } | |
48 | else { | |
49 | $module = _backer_of($pkg); | |
50 | } | |
51 | my $e = do{ | |
52 | local $@; | |
53 | eval "package $pkg;\n" | |
54 | . '$module->unimport();'; | |
55 | $@; | |
56 | }; | |
57 | Carp::croak("Cannot unimport Any::Moose: $e") if $e; | |
58 | return; | |
49 | 59 | } |
50 | 60 | |
51 | 61 | sub _backer_of { |
52 | 62 | my $pkg = shift; |
53 | 63 | |
54 | return 'Mouse' if $INC{'Mouse.pm'} | |
55 | && Mouse::Meta::Class->_metaclass_cache($pkg); | |
56 | return 'Mouse::Role' if $INC{'Mouse/Role.pm'} | |
57 | && Mouse::Meta::Role->_metaclass_cache($pkg); | |
64 | if(exists $INC{'Mouse.pm'}){ | |
65 | my $meta = Mouse::Util::get_metaclass_by_name($pkg); | |
66 | if ($meta) { | |
67 | return 'Mouse::Role' if $meta->isa('Mouse::Meta::Role'); | |
68 | return 'Mouse' if $meta->isa('Mouse::Meta::Class'); | |
69 | } | |
70 | } | |
58 | 71 | |
59 | 72 | if (_is_moose_loaded()) { |
60 | 73 | my $meta = Class::MOP::get_metaclass_by_name($pkg); |
96 | 109 | |
97 | 110 | require $file; |
98 | 111 | |
99 | eval "package $options->{package};\n" | |
100 | . '$module->import(@{ $options->{imports} });'; | |
112 | my $e = do { | |
113 | local $@; | |
114 | eval "package $options->{package};\n" | |
115 | . '$module->import(@{ $options->{imports} });'; | |
116 | $@; | |
117 | }; | |
118 | Carp::croak("Cannot import Any::Moose: $e") if $e; | |
119 | return; | |
101 | 120 | } |
102 | 121 | |
103 | 122 | sub any_moose { |
106 | 125 | |
107 | 126 | # Mouse gets first dibs because it doesn't introspect existing classes |
108 | 127 | |
109 | if ((_backer_of($package)||'') =~ /^Mouse/) { | |
128 | my $backer = _backer_of($package) || ''; | |
129 | ||
130 | if ($backer =~ /^Mouse/) { | |
110 | 131 | $fragment =~ s/^Moose/Mouse/; |
111 | 132 | return $fragment; |
112 | 133 | } |
113 | 134 | |
114 | return $fragment if (_backer_of($package)||'') =~ /^Moose/; | |
115 | ||
116 | # If we're loading up the backing class... | |
117 | if ($fragment eq 'Moose' || $fragment eq 'Moose::Role') { | |
118 | if (!$PREFERRED) { | |
119 | $PREFERRED = _is_moose_loaded() ? 'Moose' : 'Mouse'; | |
120 | ||
121 | (my $file = $PREFERRED . '.pm') =~ s{::}{/}g; | |
122 | require $file; | |
123 | } | |
124 | ||
125 | $fragment =~ s/^Moose/Mouse/ if mouse_is_preferred(); | |
126 | return $fragment; | |
127 | } | |
128 | ||
129 | require Carp; | |
130 | Carp::croak("Neither Moose nor Mouse backs the '$package' package."); | |
135 | return $fragment if $backer =~ /^Moose/; | |
136 | ||
137 | if (!$PREFERRED) { | |
138 | local $@; | |
139 | if (_is_moose_loaded()) { | |
140 | $PREFERRED = 'Moose'; | |
141 | } | |
142 | elsif (eval { require Mouse }) { | |
143 | $PREFERRED = 'Mouse'; | |
144 | } | |
145 | elsif (eval { require Moose }) { | |
146 | $PREFERRED = 'Moose'; | |
147 | } | |
148 | else { | |
149 | require Carp; | |
150 | Carp::confess("Unable to locate Mouse or Moose in INC"); | |
151 | } | |
152 | } | |
153 | ||
154 | $fragment =~ s/^Moose/Mouse/ if mouse_is_preferred(); | |
155 | return $fragment; | |
131 | 156 | } |
132 | 157 | |
133 | 158 | sub load_class { |
145 | 170 | sub moose_is_preferred { $PREFERRED eq 'Moose' } |
146 | 171 | sub mouse_is_preferred { $PREFERRED eq 'Mouse' } |
147 | 172 | |
148 | sub _is_moose_loaded { !!$INC{'Class/MOP.pm'} } | |
173 | sub _is_moose_loaded { exists $INC{'Class/MOP.pm'} } | |
149 | 174 | |
150 | 175 | sub is_moose_loaded { |
151 | 176 | Carp::carp("Any::Moose::is_moose_loaded is deprecated. Please use Any::Moose::moose_is_preferred instead"); |
155 | 180 | sub _canonicalize_fragment { |
156 | 181 | my $fragment = shift; |
157 | 182 | |
158 | return 'Moose' if !defined($fragment); | |
183 | return 'Moose' if !$fragment; | |
159 | 184 | |
160 | 185 | # any_moose("X::Types") -> any_moose("MooseX::Types") |
161 | 186 | $fragment =~ s/^X::/MooseX::/; |
169 | 194 | # any_moose("Util") -> any_moose("Moose::Util") |
170 | 195 | $fragment =~ s/^(?!Moose)/Moose::/; |
171 | 196 | |
172 | # any_moose("Moose::") (via any_moose("")) -> any_moose("Moose") | |
173 | $fragment =~ s/^Moose::$/Moose/; | |
174 | ||
175 | 197 | return $fragment; |
176 | 198 | } |
177 | 199 | |
178 | 200 | 1; |
179 | 201 | |
180 | 202 | |
181 | __END__ | |
203 | =pod | |
204 | ||
182 | 205 | =head1 NAME |
183 | 206 | |
184 | 207 | Any::Moose - use Moose or Mouse modules |
185 | 208 | |
186 | 209 | =head1 VERSION |
187 | 210 | |
188 | version 0.10 | |
211 | version 0.11 | |
189 | 212 | |
190 | 213 | =head1 SYNOPSIS |
191 | 214 | |
195 | 218 | |
196 | 219 | # uses Moose if it's loaded, Mouse otherwise |
197 | 220 | use Any::Moose; |
221 | ||
222 | # cleans the namespace up | |
223 | no Any::Moose; | |
198 | 224 | |
199 | 225 | =head2 OTHER MODULES |
200 | 226 | |
229 | 255 | Actual documentation is forthcoming, once we solidify all the bits of the API. |
230 | 256 | The examples above are very likely to continue working. |
231 | 257 | |
258 | =head1 SEE ALSO | |
259 | ||
260 | L<Moose> | |
261 | ||
262 | L<Mouse> | |
263 | ||
232 | 264 | =head1 AUTHORS |
233 | 265 | |
234 | 266 | Shawn M Moore <sartak@bestpractical.com> |
235 | 267 | Florian Ragwitz <rafl@debian.org> |
236 | 268 | Stevan Little <stevan@iinteractive.com> |
237 | 269 | Tokuhiro Matsuno <tokuhirom@gmail.com> |
270 | Goro Fuji <gfuji@cpan.org> | |
238 | 271 | |
239 | 272 | =head1 COPYRIGHT AND LICENSE |
240 | 273 | |
243 | 276 | This is free software; you can redistribute it and/or modify it under |
244 | 277 | the same terms as perl itself. |
245 | 278 | |
279 | =cut | |
280 | ||
281 | ||
282 | __END__ | |
283 |
0 | 0 | #!/usr/bin/env perl |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | use Test::More tests => 9; | |
3 | use Test::More; | |
4 | 4 | |
5 | 5 | BEGIN { delete $ENV{ANY_MOOSE} } |
6 | ||
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 9; | |
11 | } | |
6 | 12 | |
7 | 13 | do { |
8 | 14 | package Moused::Any::Moose; |
0 | 0 | #!/usr/bin/env perl |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | use Test::More tests => 2; | |
3 | use Test::More; | |
4 | 4 | |
5 | 5 | BEGIN { delete $ENV{ANY_MOOSE} } |
6 | ||
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 2; | |
11 | } | |
6 | 12 | |
7 | 13 | do { |
8 | 14 | package Moused::Any::Moose; |
10 | 16 | use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as']; |
11 | 17 | |
12 | 18 | subtype 'XYZ' => as 'Int'; |
13 | ::ok(Mouse::Util::TypeConstraints::optimized_constraints()->{XYZ}, 'subtype used Mouse'); | |
19 | ::ok(Mouse::Util::TypeConstraints::find_type_constraint('XYZ'), 'subtype used Mouse'); | |
14 | 20 | }; |
15 | 21 | |
16 | 22 | SKIP: { |
25 | 31 | use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as']; |
26 | 32 | |
27 | 33 | subtype 'ABC' => as 'Int'; |
28 | #::ok(Mouse::Util::TypeConstraints::find_type_constraint('ABC'), 'subtype used Mouse'); | |
29 | ::ok(Mouse::Util::TypeConstraints::optimized_constraints()->{ABC}, 'subtype used Mouse'); | |
34 | ::ok(Mouse::Util::TypeConstraints::find_type_constraint('ABC'), 'subtype used Mouse'); | |
30 | 35 | }; |
31 | 36 | }; |
32 | 37 |
0 | 0 | #!/usr/bin/env perl |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | use Test::More tests => 3; | |
3 | use Test::More; | |
4 | 4 | |
5 | 5 | BEGIN { delete $ENV{ANY_MOOSE} } |
6 | ||
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 3; | |
11 | } | |
6 | 12 | |
7 | 13 | package Test; |
8 | 14 | BEGIN { |
4 | 4 | |
5 | 5 | BEGIN { delete $ENV{ANY_MOOSE} } |
6 | 6 | |
7 | plan tests => 2; | |
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 2; | |
11 | } | |
8 | 12 | |
9 | 13 | { |
10 | 14 | package MyFoo; |
0 | 0 | #!/usr/bin/env perl |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | use Test::More tests => 1; | |
3 | use Test::More; | |
4 | 4 | |
5 | 5 | BEGIN { delete $ENV{ANY_MOOSE} } |
6 | ||
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 1; | |
11 | } | |
6 | 12 | |
7 | 13 | { |
8 | 14 | package My::Role; |
10 | 16 | } |
11 | 17 | |
12 | 18 | isa_ok(My::Role->meta, 'Mouse::Meta::Role'); |
19 |
0 | #!/usr/bin/env perl | |
1 | use strict; | |
2 | use warnings; | |
3 | use Test::More; | |
4 | ||
5 | BEGIN { delete $ENV{ANY_MOOSE} } | |
6 | ||
7 | BEGIN { | |
8 | eval 'require Moose'; | |
9 | plan skip_all => 'Moose not available' if $@; | |
10 | plan tests => 2; | |
11 | } | |
12 | ||
13 | { | |
14 | package My::Package; | |
15 | use Any::Moose '::Util::TypeConstraints' => [qw(type)]; | |
16 | ||
17 | ::ok defined(&type); | |
18 | ||
19 | no Any::Moose '::Util::TypeConstraints'; | |
20 | } | |
21 | ||
22 | ok !My::Package->can('type'); |
0 | #!/usr/bin/env perl | |
1 | use strict; | |
2 | use warnings; | |
3 | use Test::More; | |
4 | ||
5 | BEGIN { delete $ENV{ANY_MOOSE} } | |
6 | ||
7 | BEGIN { | |
8 | eval 'require Mouse'; | |
9 | plan skip_all => 'Mouse not available' if $@; | |
10 | plan tests => 2; | |
11 | } | |
12 | ||
13 | { | |
14 | package My::Package; | |
15 | use Any::Moose '::Util::TypeConstraints' => [qw(type)]; | |
16 | ||
17 | ::ok defined(&type); | |
18 | ||
19 | no Any::Moose '::Util::TypeConstraints'; | |
20 | } | |
21 | ||
22 | ok !My::Package->can('type'); |
0 | #!/usr/bin/env perl | |
1 | use strict; | |
2 | use warnings; | |
3 | use Test::More tests => 3; | |
4 | use Any::Moose(); | |
5 | ||
6 | $@ = 'Foo'; | |
7 | ||
8 | Any::Moose::any_moose(); | |
9 | ||
10 | is $@, 'Foo', 'any_moose() does not clear $@'; | |
11 | ||
12 | { | |
13 | package X; | |
14 | Any::Moose->import; | |
15 | } | |
16 | ||
17 | is $@, 'Foo', 'Any::Moose->import does not clear $@'; | |
18 | ||
19 | { | |
20 | package X; | |
21 | Any::Moose->unimport; | |
22 | } | |
23 | ||
24 | is $@, 'Foo', 'Any::Moose->unimport does not clear $@'; |
0 | #!perl | |
1 | ||
2 | BEGIN { | |
3 | unless ($ENV{RELEASE_TESTING}) { | |
4 | require Test::More; | |
5 | Test::More::plan(skip_all => 'these tests are for release candidate testing'); | |
6 | } | |
7 | } | |
8 | ||
9 | ||
10 | use Test::More; | |
11 | ||
12 | eval "use Test::Pod::Coverage 1.08"; | |
13 | plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" | |
14 | if $@; | |
15 | ||
16 | eval "use Pod::Coverage::TrustPod"; | |
17 | plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" | |
18 | if $@; | |
19 | ||
20 | all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' });⏎ |
0 | #!perl | |
1 | ||
2 | BEGIN { | |
3 | unless ($ENV{RELEASE_TESTING}) { | |
4 | require Test::More; | |
5 | Test::More::plan(skip_all => 'these tests are for release candidate testing'); | |
6 | } | |
7 | } | |
8 | ||
9 | use Test::More; | |
10 | ||
11 | eval "use Test::Pod 1.00"; | |
12 | plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; | |
13 | ||
14 | all_pod_files_ok();⏎ |