Codebase list libany-moose-perl / 5337d43
[svn-upgrade] Integrating new upstream version, libany-moose-perl (0.11) Jonathan Yu 14 years ago
17 changed file(s) with 260 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
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
08 0.10 Fri 19 Jun 2009
19 * Fix META.yml
210
1616 t/005-is_class_loaded-mouse.t
1717 t/010-use_mouse_roles.t
1818 t/011-use_moose_roles.t
19 t/012-use_moose_util.t
20 t/012-use_mouse_util.t
1921 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
44 - 'Florian Ragwitz <rafl@debian.org>'
55 - 'Stevan Little <stevan@iinteractive.com>'
66 - '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'
89 license: perl
910 meta-spec:
1011 url: http://module-build.sourceforge.net/META-spec-v1.4.html
1112 version: 1.4
1213 name: Any-Moose
1314 requires:
14 Mouse: 0.21
15 version: 0.10
15 Mouse: 0.40
16 perl: 5.006_002
17 version: 0.11
00
11 use strict;
22 use warnings;
3
4 BEGIN { require 5.006_002; }
35
46 use ExtUtils::MakeMaker;
57
68 WriteMakefile(
79 DISTNAME => 'Any-Moose',
810 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',
1214 EXE_FILES => [ qw() ],
13 (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
15 (eval { ExtUtils::MakeMaker->VERSION(6.31) } ? (LICENSE => 'perl') : ()),
1416 PREREQ_PM => {
15 "Mouse" => '0.21',
17 "Mouse" => '0.40',
1618 },
19 test => {TESTS => 't/*.t'}
1720 );
21
00
11
22 This archive contains the distribution Any-Moose, version
3 0.10:
3 0.11:
44
55 use Moose or Mouse modules
66
00 name = Any-Moose
1 version = 0.10
1 version = 0.11
22 author = Shawn M Moore <sartak@bestpractical.com>
33 author = Florian Ragwitz <rafl@debian.org>
44 author = Stevan Little <stevan@iinteractive.com>
55 author = Tokuhiro Matsuno <tokuhirom@gmail.com>
6 author = Goro Fuji <gfuji@cpan.org>
67 license = Perl_5
78 copyright_holder = Best Practical Solutions
89
1314 [PodWeaver]
1415
1516 [Prereq]
16 Mouse = 0.21
17
17 Mouse = 0.40
18 perl = 5.006_002
00 package Any::Moose;
1 our $VERSION = '0.10';
2
1 our $VERSION = '0.11';
32 # ABSTRACT: use Moose or Mouse modules
43
4 use 5.006_002;
55 use strict;
66 use warnings;
7
8 use Carp ();
79
810 our $PREFERRED = $ENV{'ANY_MOOSE'};
911
1113 my $self = shift;
1214 my $pkg = caller;
1315
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;
2019
2120 # first options are for Mo*se
2221 unshift @_, 'Moose' if !@_ || ref($_[0]);
3938 }
4039
4140 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;
4959 }
5060
5161 sub _backer_of {
5262 my $pkg = shift;
5363
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 }
5871
5972 if (_is_moose_loaded()) {
6073 my $meta = Class::MOP::get_metaclass_by_name($pkg);
96109
97110 require $file;
98111
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;
101120 }
102121
103122 sub any_moose {
106125
107126 # Mouse gets first dibs because it doesn't introspect existing classes
108127
109 if ((_backer_of($package)||'') =~ /^Mouse/) {
128 my $backer = _backer_of($package) || '';
129
130 if ($backer =~ /^Mouse/) {
110131 $fragment =~ s/^Moose/Mouse/;
111132 return $fragment;
112133 }
113134
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;
131156 }
132157
133158 sub load_class {
145170 sub moose_is_preferred { $PREFERRED eq 'Moose' }
146171 sub mouse_is_preferred { $PREFERRED eq 'Mouse' }
147172
148 sub _is_moose_loaded { !!$INC{'Class/MOP.pm'} }
173 sub _is_moose_loaded { exists $INC{'Class/MOP.pm'} }
149174
150175 sub is_moose_loaded {
151176 Carp::carp("Any::Moose::is_moose_loaded is deprecated. Please use Any::Moose::moose_is_preferred instead");
155180 sub _canonicalize_fragment {
156181 my $fragment = shift;
157182
158 return 'Moose' if !defined($fragment);
183 return 'Moose' if !$fragment;
159184
160185 # any_moose("X::Types") -> any_moose("MooseX::Types")
161186 $fragment =~ s/^X::/MooseX::/;
169194 # any_moose("Util") -> any_moose("Moose::Util")
170195 $fragment =~ s/^(?!Moose)/Moose::/;
171196
172 # any_moose("Moose::") (via any_moose("")) -> any_moose("Moose")
173 $fragment =~ s/^Moose::$/Moose/;
174
175197 return $fragment;
176198 }
177199
178200 1;
179201
180202
181 __END__
203 =pod
204
182205 =head1 NAME
183206
184207 Any::Moose - use Moose or Mouse modules
185208
186209 =head1 VERSION
187210
188 version 0.10
211 version 0.11
189212
190213 =head1 SYNOPSIS
191214
195218
196219 # uses Moose if it's loaded, Mouse otherwise
197220 use Any::Moose;
221
222 # cleans the namespace up
223 no Any::Moose;
198224
199225 =head2 OTHER MODULES
200226
229255 Actual documentation is forthcoming, once we solidify all the bits of the API.
230256 The examples above are very likely to continue working.
231257
258 =head1 SEE ALSO
259
260 L<Moose>
261
262 L<Mouse>
263
232264 =head1 AUTHORS
233265
234266 Shawn M Moore <sartak@bestpractical.com>
235267 Florian Ragwitz <rafl@debian.org>
236268 Stevan Little <stevan@iinteractive.com>
237269 Tokuhiro Matsuno <tokuhirom@gmail.com>
270 Goro Fuji <gfuji@cpan.org>
238271
239272 =head1 COPYRIGHT AND LICENSE
240273
243276 This is free software; you can redistribute it and/or modify it under
244277 the same terms as perl itself.
245278
279 =cut
280
281
282 __END__
283
00 #!/usr/bin/env perl
11 use strict;
22 use warnings;
3 use Test::More tests => 9;
3 use Test::More;
44
55 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 }
612
713 do {
814 package Moused::Any::Moose;
00 #!/usr/bin/env perl
11 use strict;
22 use warnings;
3 use Test::More tests => 2;
3 use Test::More;
44
55 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 }
612
713 do {
814 package Moused::Any::Moose;
1016 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
1117
1218 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');
1420 };
1521
1622 SKIP: {
2531 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
2632
2733 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');
3035 };
3136 };
3237
00 #!/usr/bin/env perl
11 use strict;
22 use warnings;
3 use Test::More tests => 3;
3 use Test::More;
44
55 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 }
612
713 package Test;
814 BEGIN {
44
55 BEGIN { delete $ENV{ANY_MOOSE} }
66
7 plan tests => 2;
7 BEGIN {
8 eval 'require Mouse';
9 plan skip_all => 'Mouse not available' if $@;
10 plan tests => 2;
11 }
812
913 {
1014 package MyFoo;
00 #!/usr/bin/env perl
11 use strict;
22 use warnings;
3 use Test::More tests => 1;
3 use Test::More;
44
55 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 }
612
713 {
814 package My::Role;
1016 }
1117
1218 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();