Codebase list libany-moose-perl / 4126687
[svn-inject] Installing original source of libany-moose-perl Ryan Niebur 15 years ago
21 changed file(s) with 1078 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 0.07 Fri, 10 Apr 2009
1 * Depend on Mouse 0.20 for better compatibility with Moose >= 0.74 (rafl).
2
3 0.06 Wed, 18 Mar 2009
4 * Add Any::Moose::is_class_loaded. (tokuhirom)
5
6 0.05 Wed, 25 Feb 2009
7 * Stop using ambiguous ways of creating named subtypes in the tests. This
8 makes them pass again with Moose >= 0.72. (rafl)
9
10 0.04 Tue, 17 Feb 2009
11 * Any::Moose now gives you strict and warnings (oops!)
12 * Support "use Any::Moose 'X::Types'" (tokuhirom)
13
14 0.03 Mon, 09 Feb 2009
15 * When we load one of Mo*se, we'll continue to load that backer even if
16 Moose had become loaded
17 * Skip some tests if Moose is not installed
18 * Hard dependency on Mouse
19
20 0.02 Sun, 08 Feb 2009
21 * Fix compilation error (rafl)
22 * Add load_class and is_moose_loaded (stevan)
23
24 0.01 Sun, 05 Feb 2009
25 * Initial release
26
0 This software is copyright (c) 2009 by Best Practical Solutions.
1
2 This is free software; you can redistribute it and/or modify it under
3 the same terms as perl itself.
4
5 Terms of Perl itself
6
7 a) the GNU General Public License as published by the Free
8 Software Foundation; either version 1, or (at your option) any
9 later version, or
10 b) the "Artistic License"
11
12 --- The GNU General Public License, Version 1, February 1989 ---
13
14 This software is Copyright (c) 2009 by Best Practical Solutions.
15
16 This is free software, licensed under:
17
18 The GNU General Public License, Version 1, February 1989
19
20 GNU GENERAL PUBLIC LICENSE
21 Version 1, February 1989
22
23 Copyright (C) 1989 Free Software Foundation, Inc.
24 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
25 Everyone is permitted to copy and distribute verbatim copies
26 of this license document, but changing it is not allowed.
27
28 Preamble
29
30 The license agreements of most software companies try to keep users
31 at the mercy of those companies. By contrast, our General Public
32 License is intended to guarantee your freedom to share and change free
33 software--to make sure the software is free for all its users. The
34 General Public License applies to the Free Software Foundation's
35 software and to any other program whose authors commit to using it.
36 You can use it for your programs, too.
37
38 When we speak of free software, we are referring to freedom, not
39 price. Specifically, the General Public License is designed to make
40 sure that you have the freedom to give away or sell copies of free
41 software, that you receive source code or can get it if you want it,
42 that you can change the software or use pieces of it in new free
43 programs; and that you know you can do these things.
44
45 To protect your rights, we need to make restrictions that forbid
46 anyone to deny you these rights or to ask you to surrender the rights.
47 These restrictions translate to certain responsibilities for you if you
48 distribute copies of the software, or if you modify it.
49
50 For example, if you distribute copies of a such a program, whether
51 gratis or for a fee, you must give the recipients all the rights that
52 you have. You must make sure that they, too, receive or can get the
53 source code. And you must tell them their rights.
54
55 We protect your rights with two steps: (1) copyright the software, and
56 (2) offer you this license which gives you legal permission to copy,
57 distribute and/or modify the software.
58
59 Also, for each author's protection and ours, we want to make certain
60 that everyone understands that there is no warranty for this free
61 software. If the software is modified by someone else and passed on, we
62 want its recipients to know that what they have is not the original, so
63 that any problems introduced by others will not reflect on the original
64 authors' reputations.
65
66 The precise terms and conditions for copying, distribution and
67 modification follow.
68
69 GNU GENERAL PUBLIC LICENSE
70 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
71
72 0. This License Agreement applies to any program or other work which
73 contains a notice placed by the copyright holder saying it may be
74 distributed under the terms of this General Public License. The
75 "Program", below, refers to any such program or work, and a "work based
76 on the Program" means either the Program or any work containing the
77 Program or a portion of it, either verbatim or with modifications. Each
78 licensee is addressed as "you".
79
80 1. You may copy and distribute verbatim copies of the Program's source
81 code as you receive it, in any medium, provided that you conspicuously and
82 appropriately publish on each copy an appropriate copyright notice and
83 disclaimer of warranty; keep intact all the notices that refer to this
84 General Public License and to the absence of any warranty; and give any
85 other recipients of the Program a copy of this General Public License
86 along with the Program. You may charge a fee for the physical act of
87 transferring a copy.
88
89 2. You may modify your copy or copies of the Program or any portion of
90 it, and copy and distribute such modifications under the terms of Paragraph
91 1 above, provided that you also do the following:
92
93 a) cause the modified files to carry prominent notices stating that
94 you changed the files and the date of any change; and
95
96 b) cause the whole of any work that you distribute or publish, that
97 in whole or in part contains the Program or any part thereof, either
98 with or without modifications, to be licensed at no charge to all
99 third parties under the terms of this General Public License (except
100 that you may choose to grant warranty protection to some or all
101 third parties, at your option).
102
103 c) If the modified program normally reads commands interactively when
104 run, you must cause it, when started running for such interactive use
105 in the simplest and most usual way, to print or display an
106 announcement including an appropriate copyright notice and a notice
107 that there is no warranty (or else, saying that you provide a
108 warranty) and that users may redistribute the program under these
109 conditions, and telling the user how to view a copy of this General
110 Public License.
111
112 d) You may charge a fee for the physical act of transferring a
113 copy, and you may at your option offer warranty protection in
114 exchange for a fee.
115
116 Mere aggregation of another independent work with the Program (or its
117 derivative) on a volume of a storage or distribution medium does not bring
118 the other work under the scope of these terms.
119
120 3. You may copy and distribute the Program (or a portion or derivative of
121 it, under Paragraph 2) in object code or executable form under the terms of
122 Paragraphs 1 and 2 above provided that you also do one of the following:
123
124 a) accompany it with the complete corresponding machine-readable
125 source code, which must be distributed under the terms of
126 Paragraphs 1 and 2 above; or,
127
128 b) accompany it with a written offer, valid for at least three
129 years, to give any third party free (except for a nominal charge
130 for the cost of distribution) a complete machine-readable copy of the
131 corresponding source code, to be distributed under the terms of
132 Paragraphs 1 and 2 above; or,
133
134 c) accompany it with the information you received as to where the
135 corresponding source code may be obtained. (This alternative is
136 allowed only for noncommercial distribution and only if you
137 received the program in object code or executable form alone.)
138
139 Source code for a work means the preferred form of the work for making
140 modifications to it. For an executable file, complete source code means
141 all the source code for all modules it contains; but, as a special
142 exception, it need not include source code for modules which are standard
143 libraries that accompany the operating system on which the executable
144 file runs, or for standard header files or definitions files that
145 accompany that operating system.
146
147 4. You may not copy, modify, sublicense, distribute or transfer the
148 Program except as expressly provided under this General Public License.
149 Any attempt otherwise to copy, modify, sublicense, distribute or transfer
150 the Program is void, and will automatically terminate your rights to use
151 the Program under this License. However, parties who have received
152 copies, or rights to use copies, from you under this General Public
153 License will not have their licenses terminated so long as such parties
154 remain in full compliance.
155
156 5. By copying, distributing or modifying the Program (or any work based
157 on the Program) you indicate your acceptance of this license to do so,
158 and all its terms and conditions.
159
160 6. Each time you redistribute the Program (or any work based on the
161 Program), the recipient automatically receives a license from the original
162 licensor to copy, distribute or modify the Program subject to these
163 terms and conditions. You may not impose any further restrictions on the
164 recipients' exercise of the rights granted herein.
165
166 7. The Free Software Foundation may publish revised and/or new versions
167 of the General Public License from time to time. Such new versions will
168 be similar in spirit to the present version, but may differ in detail to
169 address new problems or concerns.
170
171 Each version is given a distinguishing version number. If the Program
172 specifies a version number of the license which applies to it and "any
173 later version", you have the option of following the terms and conditions
174 either of that version or of any later version published by the Free
175 Software Foundation. If the Program does not specify a version number of
176 the license, you may choose any version ever published by the Free Software
177 Foundation.
178
179 8. If you wish to incorporate parts of the Program into other free
180 programs whose distribution conditions are different, write to the author
181 to ask for permission. For software which is copyrighted by the Free
182 Software Foundation, write to the Free Software Foundation; we sometimes
183 make exceptions for this. Our decision will be guided by the two goals
184 of preserving the free status of all derivatives of our free software and
185 of promoting the sharing and reuse of software generally.
186
187 NO WARRANTY
188
189 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
190 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
191 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
192 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
193 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
194 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
195 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
196 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
197 REPAIR OR CORRECTION.
198
199 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
200 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
201 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
202 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
203 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
204 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
205 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
206 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
207 POSSIBILITY OF SUCH DAMAGES.
208
209 END OF TERMS AND CONDITIONS
210
211 Appendix: How to Apply These Terms to Your New Programs
212
213 If you develop a new program, and you want it to be of the greatest
214 possible use to humanity, the best way to achieve this is to make it
215 free software which everyone can redistribute and change under these
216 terms.
217
218 To do so, attach the following notices to the program. It is safest to
219 attach them to the start of each source file to most effectively convey
220 the exclusion of warranty; and each file should have at least the
221 "copyright" line and a pointer to where the full notice is found.
222
223 <one line to give the program's name and a brief idea of what it does.>
224 Copyright (C) 19yy <name of author>
225
226 This program is free software; you can redistribute it and/or modify
227 it under the terms of the GNU General Public License as published by
228 the Free Software Foundation; either version 1, or (at your option)
229 any later version.
230
231 This program is distributed in the hope that it will be useful,
232 but WITHOUT ANY WARRANTY; without even the implied warranty of
233 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234 GNU General Public License for more details.
235
236 You should have received a copy of the GNU General Public License
237 along with this program; if not, write to the Free Software Foundation,
238 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
239
240 Also add information on how to contact you by electronic and paper mail.
241
242 If the program is interactive, make it output a short notice like this
243 when it starts in an interactive mode:
244
245 Gnomovision version 69, Copyright (C) 19xx name of author
246 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
247 This is free software, and you are welcome to redistribute it
248 under certain conditions; type `show c' for details.
249
250 The hypothetical commands `show w' and `show c' should show the
251 appropriate parts of the General Public License. Of course, the
252 commands you use may be called something other than `show w' and `show
253 c'; they could even be mouse-clicks or menu items--whatever suits your
254 program.
255
256 You should also get your employer (if you work as a programmer) or your
257 school, if any, to sign a "copyright disclaimer" for the program, if
258 necessary. Here a sample; alter the names:
259
260 Yoyodyne, Inc., hereby disclaims all copyright interest in the
261 program `Gnomovision' (a program to direct compilers to make passes
262 at assemblers) written by James Hacker.
263
264 <signature of Ty Coon>, 1 April 1989
265 Ty Coon, President of Vice
266
267 That's all there is to it!
268
269
270 --- The Artistic License 1.0 ---
271
272 This software is Copyright (c) 2009 by Best Practical Solutions.
273
274 This is free software, licensed under:
275
276 The Artistic License 1.0
277
278 The Artistic License
279
280 Preamble
281
282 The intent of this document is to state the conditions under which a Package
283 may be copied, such that the Copyright Holder maintains some semblance of
284 artistic control over the development of the package, while giving the users of
285 the package the right to use and distribute the Package in a more-or-less
286 customary fashion, plus the right to make reasonable modifications.
287
288 Definitions:
289
290 - "Package" refers to the collection of files distributed by the Copyright
291 Holder, and derivatives of that collection of files created through
292 textual modification.
293 - "Standard Version" refers to such a Package if it has not been modified,
294 or has been modified in accordance with the wishes of the Copyright
295 Holder.
296 - "Copyright Holder" is whoever is named in the copyright or copyrights for
297 the package.
298 - "You" is you, if you're thinking about copying or distributing this Package.
299 - "Reasonable copying fee" is whatever you can justify on the basis of media
300 cost, duplication charges, time of people involved, and so on. (You will
301 not be required to justify it to the Copyright Holder, but only to the
302 computing community at large as a market that must bear the fee.)
303 - "Freely Available" means that no fee is charged for the item itself, though
304 there may be fees involved in handling the item. It also means that
305 recipients of the item may redistribute it under the same conditions they
306 received it.
307
308 1. You may make and give away verbatim copies of the source form of the
309 Standard Version of this Package without restriction, provided that you
310 duplicate all of the original copyright notices and associated disclaimers.
311
312 2. You may apply bug fixes, portability fixes and other modifications derived
313 from the Public Domain or from the Copyright Holder. A Package modified in such
314 a way shall still be considered the Standard Version.
315
316 3. You may otherwise modify your copy of this Package in any way, provided that
317 you insert a prominent notice in each changed file stating how and when you
318 changed that file, and provided that you do at least ONE of the following:
319
320 a) place your modifications in the Public Domain or otherwise make them
321 Freely Available, such as by posting said modifications to Usenet or an
322 equivalent medium, or placing the modifications on a major archive site
323 such as ftp.uu.net, or by allowing the Copyright Holder to include your
324 modifications in the Standard Version of the Package.
325
326 b) use the modified Package only within your corporation or organization.
327
328 c) rename any non-standard executables so the names do not conflict with
329 standard executables, which must also be provided, and provide a separate
330 manual page for each non-standard executable that clearly documents how it
331 differs from the Standard Version.
332
333 d) make other distribution arrangements with the Copyright Holder.
334
335 4. You may distribute the programs of this Package in object code or executable
336 form, provided that you do at least ONE of the following:
337
338 a) distribute a Standard Version of the executables and library files,
339 together with instructions (in the manual page or equivalent) on where to
340 get the Standard Version.
341
342 b) accompany the distribution with the machine-readable source of the Package
343 with your modifications.
344
345 c) accompany any non-standard executables with their corresponding Standard
346 Version executables, giving the non-standard executables non-standard
347 names, and clearly documenting the differences in manual pages (or
348 equivalent), together with instructions on where to get the Standard
349 Version.
350
351 d) make other distribution arrangements with the Copyright Holder.
352
353 5. You may charge a reasonable copying fee for any distribution of this
354 Package. You may charge any fee you choose for support of this Package. You
355 may not charge a fee for this Package itself. However, you may distribute this
356 Package in aggregate with other (possibly commercial) programs as part of a
357 larger (possibly commercial) software distribution provided that you do not
358 advertise this Package as a product of your own.
359
360 6. The scripts and library files supplied as input to or produced as output
361 from the programs of this Package do not automatically fall under the copyright
362 of this Package, but belong to whomever generated them, and may be sold
363 commercially, and may be aggregated with this Package.
364
365 7. C or perl subroutines supplied by you and linked into this Package shall not
366 be considered part of this Package.
367
368 8. The name of the Copyright Holder may not be used to endorse or promote
369 products derived from this software without specific prior written permission.
370
371 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
372 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
373 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
374
375 The End
376
0 Changes
1 LICENSE
2 MANIFEST
3 META.yml
4 Makefile.PL
5 README
6 dist.ini
7 lib/Any/Moose.pm
8 t/001-basic-moose.t
9 t/001-basic-mouse.t
10 t/002-other-modules-moose.t
11 t/002-other-modules-mouse.t
12 t/003-is_moose_loaded.t
13 t/004-x-modules-moose.t
14 t/004-x-modules-mouse.t
15 t/005-is_class_loaded-moose.t
16 t/005-is_class_loaded-mouse.t
17 t/010-use_mouse_roles.t
18 t/011-use_moose_roles.t
19 t/020-strict.t
20 t/100-canonicalize-fragments.t
0 ---
1 abstract: use Moose or Mouse modules
2 author:
3 - Shawn M Moore <sartak@bestpractical.com>
4 - Florian Ragwitz <rafl@debian.org>
5 - Stevan Little <stevan@iinteractive.com>
6 - Tokuhiro Matsuno <tokuhirom@gmail.com>
7 generated_by: Dist::Zilla::Plugin::MetaYaml version 1.004
8 license: perl
9 name: Any-Moose
10 requires:
11 Mouse: 0.20
12 version: 0.07
0
1 use strict;
2 use warnings;
3
4 use ExtUtils::MakeMaker;
5
6 WriteMakefile(
7 DISTNAME => 'Any-Moose',
8 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.07',
12 EXE_FILES => [ qw() ],
13 (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
14 PREREQ_PM => {
15 "Mouse" => '0.20',
16 },
17 );
0
1
2 This archive contains the distribution Any-Moose, version
3 0.07:
4
5 use Moose or Mouse modules
6
7 This software is copyright (c) 2009 by Best Practical Solutions.
8
9 This is free software; you can redistribute it and/or modify it under
10 the same terms as perl itself.
11
0 name = Any-Moose
1 version = 0.07
2 author = Shawn M Moore <sartak@bestpractical.com>
3 author = Florian Ragwitz <rafl@debian.org>
4 author = Stevan Little <stevan@iinteractive.com>
5 author = Tokuhiro Matsuno <tokuhirom@gmail.com>
6 license = Perl_5
7 copyright_holder = Best Practical Solutions
8
9 [@Classic]
10
11 [PodWeaver]
12
13 [Prereq]
14 Mouse = 0.20
15
0 package Any::Moose;
1 our $VERSION = '0.07';
2
3 # ABSTRACT: use Moose or Mouse modules
4
5 use strict;
6 use warnings;
7
8 our $PREFERRED = $ENV{'ANY_MOOSE'};
9
10 sub import {
11 my $self = shift;
12 my $pkg = caller;
13
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 }
20
21 # first options are for Mo*se
22 unshift @_, 'Moose' if !@_ || ref($_[0]);
23
24 while (my $module = shift) {
25 my $options = @_ && ref($_[0]) ? shift : [];
26
27 $options = $self->_canonicalize_options(
28 module => $module,
29 options => $options,
30 package => $pkg,
31 );
32
33 $self->_install_module($options);
34 }
35
36 # give them any_moose too
37 no strict 'refs';
38 *{$pkg.'::any_moose'} = \&any_moose;
39 }
40
41 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(@_);';
49 }
50
51 sub _backer_of {
52 my $pkg = shift;
53
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);
58
59 if (is_moose_loaded()) {
60 my $meta = Class::MOP::get_metaclass_by_name($pkg);
61 if ($meta) {
62 return 'Moose::Role' if $meta->isa('Moose::Meta::Role');
63 return 'Moose' if $meta->isa('Moose::Meta::Class');
64 }
65 }
66
67 return undef;
68 }
69
70 sub _canonicalize_options {
71 my $self = shift;
72 my %args = @_;
73
74 my %options;
75 if (ref($args{options}) eq 'HASH') {
76 %options = %{ $args{options} };
77 }
78 else {
79 %options = (
80 imports => $args{options},
81 );
82 }
83
84 $options{package} = $args{package};
85 $options{module} = any_moose($args{module}, $args{package});
86
87 return \%options;
88 }
89
90 sub _install_module {
91 my $self = shift;
92 my $options = shift;
93
94 my $module = $options->{module};
95 (my $file = $module . '.pm') =~ s{::}{/}g;
96
97 require $file;
98
99 eval "package $options->{package};\n"
100 . '$module->import(@{ $options->{imports} });';
101 }
102
103 sub any_moose {
104 my $fragment = _canonicalize_fragment(shift);
105 my $package = shift || caller;
106
107 # Mouse gets first dibs because it doesn't introspect existing classes
108
109 if ((_backer_of($package)||'') =~ /^Mouse/) {
110 $fragment =~ s/^Moose/Mouse/;
111 return $fragment;
112 }
113
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 $PREFERRED eq 'Mouse';
126 return $fragment;
127 }
128
129 require Carp;
130 Carp::croak("Neither Moose nor Mouse backs the '$package' package.");
131 }
132
133 sub load_class {
134 my ($class_name) = @_;
135 return Class::MOP::load_class($class_name)
136 if is_moose_loaded();
137 return Mouse::load_class($class_name);
138 }
139
140 sub is_class_loaded {
141 my ($class_name) = @_;
142 return Class::MOP::is_class_loaded($class_name)
143 if is_moose_loaded();
144 return Mouse::is_class_loaded($class_name);
145 }
146
147 sub is_moose_loaded { !!$INC{'Class/MOP.pm'} }
148
149 sub _canonicalize_fragment {
150 my $fragment = shift;
151
152 return 'Moose' if !defined($fragment);
153
154 # any_moose("X::Types") -> any_moose("MooseX::Types")
155 $fragment =~ s/^X::/MooseX::/;
156
157 # any_moose("::Util") -> any_moose("Moose::Util")
158 $fragment =~ s/^::/Moose::/;
159
160 # any_moose("Mouse::Util") -> any_moose("Moose::Util")
161 $fragment =~ s/^Mouse(X?)\b/Moose$1/;
162
163 # any_moose("Util") -> any_moose("Moose::Util")
164 $fragment =~ s/^(?!Moose)/Moose::/;
165
166 # any_moose("Moose::") (via any_moose("")) -> any_moose("Moose")
167 $fragment =~ s/^Moose::$/Moose/;
168
169 return $fragment;
170 }
171
172 1;
173
174
175 __END__
176 =head1 NAME
177
178 Any::Moose - use Moose or Mouse modules
179
180 =head1 VERSION
181
182 version 0.07
183
184 =head1 SYNOPSIS
185
186 =head2 BASIC
187
188 package Class;
189
190 # uses Moose if it's loaded, Mouse otherwise
191 use Any::Moose;
192
193 =head2 OTHER MODULES
194
195 package Other::Class;
196 use Any::Moose;
197
198 # uses Moose::Util::TypeConstraints if the class has loaded Moose,
199 # Mouse::Util::TypeConstraints otherwise.
200 use Any::Moose '::Util::TypeConstraints';
201
202 =head2 COMPLEX USAGE
203
204 package My::Meta::Class;
205 use Any::Moose;
206
207 # uses subtype from Moose::Util::TypeConstraints if the class loaded Moose,
208 # subtype from Mouse::Util::TypeConstraints otherwise.
209 # similarly for Mo*se::Util's does_role
210 use Any::Moose (
211 '::Util::TypeConstraints' => ['subtype'],
212 '::Util' => ['does_role'],
213 );
214
215 # uses MouseX::Types
216 use Any::Moose 'X::Types';
217
218 # gives you the right class name depending on which Mo*se was loaded
219 extends any_moose('::Meta::Class');
220
221 =head1 DESCRIPTION
222
223 Actual documentation is forthcoming, once we solidify all the bits of the API.
224 The examples above are very likely to continue working.
225
226 =head1 AUTHORS
227
228 Shawn M Moore <sartak@bestpractical.com>
229 Florian Ragwitz <rafl@debian.org>
230 Stevan Little <stevan@iinteractive.com>
231 Tokuhiro Matsuno <tokuhirom@gmail.com>
232
233 =head1 COPYRIGHT AND LICENSE
234
235 This software is copyright (c) 2009 by Best Practical Solutions.
236
237 This is free software; you can redistribute it and/or modify it under
238 the same terms as perl itself.
239
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More tests => 9;
4
5 BEGIN { delete $ENV{ANY_MOOSE} }
6
7 do {
8 package Moused::Any::Moose;
9 use Any::Moose;
10
11 ::ok(__PACKAGE__->can('meta'), 'Mo*se was installed');
12 ::like(__PACKAGE__->meta, qr/^Mouse/, 'Mouse was installed');
13
14 ::is(any_moose, 'Mouse');
15 ::is(any_moose('::Util::TypeConstraints'), 'Mouse::Util::TypeConstraints');
16
17 ::is(any_moose, 'Mouse', 'still Mouse even if Moose is loaded');
18
19 no Any::Moose;
20 };
21
22 ok(!Moused::Any::Moose->can('has'), "has was unimported");
23
24 SKIP: {
25 my $loaded_moose;
26 BEGIN { $loaded_moose = eval 'require Moose' }
27 skip "Moose required for these tests to be useful" => 3 unless $loaded_moose;
28
29 do {
30 package After::Moose;
31 use Any::Moose;
32
33 ::is(any_moose, 'Mouse');
34 ::is(any_moose('::Util::TypeConstraints'), 'Mouse::Util::TypeConstraints');
35
36 no Any::Moose;
37 };
38
39 ok(!After::Moose->can('has'), "has was unimported");
40 }
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 => 9;
11 }
12
13 do {
14 package Moosed::Any::Moose;
15 use Any::Moose;
16
17 ::ok(__PACKAGE__->can('meta'), 'Mo*se was installed');
18 ::like(__PACKAGE__->meta, qr/^Moose/, 'Moose was installed');
19
20 ::is(any_moose, 'Moose');
21 ::is(any_moose('::Util::TypeConstraints'), 'Moose::Util::TypeConstraints');
22
23 ::is(any_moose, 'Moose', 'still Moose even if Moose is loaded');
24
25 no Any::Moose;
26 };
27
28 ok(!Moosed::Any::Moose->can('has'), "has was unimported");
29
30 do {
31 package After::Moose;
32 use Any::Moose;
33
34 ::is(any_moose, 'Moose');
35 ::is(any_moose('::Util::TypeConstraints'), 'Moose::Util::TypeConstraints');
36
37 no Any::Moose;
38 };
39
40 ok(!After::Moose->can('has'), "has was unimported");
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 do {
14 package Moosed::Any::Moose;
15 use Any::Moose;
16 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
17
18 subtype 'XYZ' => as 'Int';
19 ::ok(Moose::Util::TypeConstraints::find_type_constraint('XYZ'), 'subtype used Moose');
20 };
21
22 do {
23 package After::Moose;
24 use Any::Moose;
25 use Any::Moose '::Util::TypeConstraints';
26 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
27
28 subtype 'ABC' => as 'Int';
29 ::ok(Moose::Util::TypeConstraints::find_type_constraint('ABC'), 'subtype used Moose');
30 };
31
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More tests => 2;
4
5 BEGIN { delete $ENV{ANY_MOOSE} }
6
7 do {
8 package Moused::Any::Moose;
9 use Any::Moose;
10 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
11
12 subtype 'XYZ' => as 'Int';
13 ::ok(Mouse::Util::TypeConstraints::optimized_constraints()->{XYZ}, 'subtype used Mouse');
14 };
15
16 SKIP: {
17 my $loaded_moose;
18 BEGIN { $loaded_moose = eval 'require Moose' }
19 skip "Moose required for these tests to be useful" => 1 unless $loaded_moose;
20
21 do {
22 package After::Moose;
23 use Any::Moose;
24 use Any::Moose '::Util::TypeConstraints';
25 use Any::Moose '::Util::TypeConstraints' => ['subtype', 'as'];
26
27 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');
30 };
31 };
32
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More tests => 3;
4
5 BEGIN { delete $ENV{ANY_MOOSE} }
6
7 package Test;
8 BEGIN {
9 ::use_ok('Any::Moose');
10 ::ok(!Any::Moose::is_moose_loaded(), '... Moose is not loaded');
11 }
12
13 {
14 package Foo;
15 BEGIN {
16 SKIP: {
17 eval 'use Moose';
18 ::skip 'Moose not installed', 1 if $@;
19
20 ::ok(Any::Moose::is_moose_loaded(), '... Moose is loaded');
21 }
22 }
23 }
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; require MooseX::Types';
9 plan skip_all => 'Moose or MooseX::Types not available' if $@;
10 plan tests => 2;
11 }
12
13 do {
14 package Moosed::Any::Moose;
15 use Any::Moose;
16 use Any::Moose 'X::Types';
17
18 ::ok(MooseX::Types->can('import'), 'MooseX::Types');
19 };
20
21 do {
22 package After::Moose;
23 use Any::Moose;
24 use Any::Moose 'X::Types';
25
26 ::ok(MooseX::Types->can('import'), 'MooseX::Types');
27 };
28
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 plan skip_all => 'MouseX::Types not available' unless eval "require MouseX::Types";
9 plan tests => 2;
10 }
11
12 do {
13 package Moused::Any::Moose;
14 use Any::Moose;
15 use Any::Moose 'X::Types';
16
17 ::ok(MouseX::Types->can('import'), 'MouseX::Types');
18 };
19
20 SKIP: {
21 my $loaded_moose;
22 BEGIN { $loaded_moose = eval 'require Moose; require MooseX::Types' }
23 skip "Moose and MooseX::Types required for these tests to be useful" => 1 unless $loaded_moose;
24
25 do {
26 package After::Moose;
27 use Any::Moose;
28 use Any::Moose 'X::Types';
29
30 ::ok(MouseX::Types->can('import'), 'MouseX::Types');
31 };
32 };
33
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 package MyFoo;
14 use Any::Moose;
15 ::ok Any::Moose::is_class_loaded('Moose');
16 ::ok !Any::Moose::is_class_loaded('Meese');
17
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More;
4
5 BEGIN { delete $ENV{ANY_MOOSE} }
6
7 plan tests => 2;
8
9 {
10 package MyFoo;
11 use Any::Moose;
12 }
13
14 package main;
15 ok(Any::Moose::is_class_loaded('Mouse'));
16 ok(!Any::Moose::is_class_loaded('Meese'));
17
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More tests => 1;
4
5 BEGIN { delete $ENV{ANY_MOOSE} }
6
7 {
8 package My::Role;
9 use Any::Moose '::Role';
10 }
11
12 isa_ok(My::Role->meta, 'Mouse::Meta::Role');
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 => 1;
11 }
12
13 {
14 package My::Role;
15 use Any::Moose '::Role';
16 }
17
18 isa_ok(My::Role->meta, 'Moose::Meta::Role');
0 #!/usr/bin/env perl
1 use Test::More tests => 1;
2
3 do {
4 package Need::Strict;
5 use Any::Moose;
6
7 eval {
8 my $foo = "ack!";
9 my $bar = '$foo';
10
11 my $garbage = $$bar;
12 };
13
14 ::ok($@, "Any::Moose gives you strictures");
15 };
16
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More;
4 require Any::Moose;
5
6 BEGIN { delete $ENV{ANY_MOOSE} }
7
8 my @tests = (
9 '' => 'Moose',
10
11 'Moose' => 'Moose',
12 'Mouse' => 'Moose',
13
14 'Moose::Util' => 'Moose::Util',
15 'Mouse::Util' => 'Moose::Util',
16 '::Util' => 'Moose::Util',
17 'Util' => 'Moose::Util',
18
19 'MooseX::Types' => 'MooseX::Types',
20 'MouseX::Types' => 'MooseX::Types',
21 'X::Types' => 'MooseX::Types',
22
23 'Moose::X::Types' => 'Moose::X::Types',
24 'Mouse::X::Types' => 'Moose::X::Types',
25 '::X::Types' => 'Moose::X::Types',
26 );
27
28 plan tests => @tests / 2;
29
30 while (my ($fragment, $expected) = splice @tests, 0, 2) {
31 my $got = Any::Moose::_canonicalize_fragment($fragment);
32 is($got, $expected, "Canonicalized '$fragment'");
33 }
34