Codebase list libmoose-perl / 6448fb9
revert half-upgraded package Jonathan Yu 14 years ago
87 changed file(s) with 219 addition(s) and 402 deletion(s). Raw diff Collapse all Expand all
00 Also see Moose::Manual::Delta for more details of, and workarounds
11 for, noteworthy changes.
2
3 0.93 Thu, Nov 19, 2009
4 * Moose::Object
5 - Calling $object->new() is no longer deprecated, and no longer
6 warns. (doy)
7
8 * Moose::Meta::Role
9 - The get_attribute_map method is now deprecated. (Dave Rolsky)
10
11 * Moose::Meta::Method::Delegation
12 - Preserve variable aliasing in @_ for delegated methods, so that
13 altering @_ affects the passed value. (doy)
14
15 * Moose::Util::TypeConstraints
16 - Allow array refs for non-anonymous form of enum and duck_type, not
17 just anonymous. The non-arrayref forms may be removed in the
18 future. (doy)
19 - Changed Str constraint to not accept globs (*STDIN or *FOO). (chansen)
20 - Properly document Int being a subtype of Str. (doy)
21
22 * Moose::Exporter
23 - Moose::Exporter using modules can now export their functions to the
24 main package. This applied to Moose and Moose::Role, among
25 others. (nothingmuch)
26
27 * Moose::Meta::Attribute
28 - Don't remove attribute accessors we never installed, during
29 remove_accessors. (doy)
30
31 * Moose::Meta::Attribute::Native::Trait::Array
32 - Don't bypass prototype checking when calling List::Util::first, to
33 avoid a segfault when it is called with a non-code argument. (doy)
34
35 * Moose::Meta::Attribute::Native::Trait::Code
36 - Fix passing arguments to code execute helpers. (doy)
372
383 0.92 Tue, Sep 22, 2009
394 * Moose::Util::TypeConstraints
8651 - Added more hooks to customize how roles are applied. The role
8752 summation class, used to create composite roles, can now be changed
8853 and/or have meta-roles applied to it. (rafl)
89 - The get_method_list method no longer explicitly excludes the "meta"
90 method. This was a hack that has been replaced by better hacks. (Dave
91 Rolsky)
9254
9355 * Moose::Meta::Method::Delegation
9456 - fixed delegated methods to make sure that any modifiers attached to
161161 t/010_basics/019-destruction.t
162162 t/010_basics/020-global-destruction-helper.pl
163163 t/010_basics/020-global-destruction.t
164 t/010_basics/021-instance-new.t
164165 t/020_attributes/001_attribute_reader_generation.t
165166 t/020_attributes/002_attribute_writer_generation.t
166167 t/020_attributes/003_attribute_accessor_generation.t
192193 t/020_attributes/029_accessor_context.t
193194 t/020_attributes/030_non_alpha_attr_names.t
194195 t/020_attributes/031_delegation_and_modifiers.t
195 t/020_attributes/032_delegation_arg_aliasing.t
196196 t/030_roles/001_meta_role.t
197197 t/030_roles/002_role.t
198198 t/030_roles/003_apply_role.t
2121 ^\._.*$
2222 ^t\/600_todo_tests\/$
2323 \.shipit
24 ^grant-description
2425 ^Moose-.*
2526 \.git.*
3232 perl: 5.8.1
3333 resources:
3434 license: http://dev.perl.org/licenses/
35 version: 0.93
35 version: 0.92
4040 'MooseX::AttributeHelpers' => '0.21',
4141 'MooseX::ClassAttribute' => '0.09',
4242 'MooseX::MethodAttributes' => '0.15',
43 'MooseX::NonMoose' => '0.05',
4443 'MooseX::Params::Validate' => '0.05',
4544 'MooseX::Singleton' => '0.19',
4645 'MooseX::StrictConstructor' => '0.07',
0 Moose version 0.93
0 Moose version 0.92
11 ===========================
22
33 See the individual module documentation for more information
3737 sub dump {
3838 my $self = shift;
3939
40 my $meta = $self->meta;
41
4240 my $dump = '';
4341
44 for my $attribute ( map { $meta->get_attribute($_) }
45 sort $meta->get_attribute_list ) {
42 my %attributes = %{ $self->meta->get_attribute_map };
43 for my $name ( sort keys %attributes ) {
44 my $attribute = $attributes{$name};
4645
4746 if ( $attribute->isa('MyApp::Meta::Attribute::Labeled')
4847 && $attribute->has_label ) {
4948 $dump .= $attribute->label;
5049 }
5150 else {
52 $dump .= $attribute->name;
51 $dump .= $name;
5352 }
5453
5554 my $reader = $attribute->get_read_method;
8786 Internally, the metaclass for C<Point> has two
8887 L<Moose::Meta::Attribute>. There are several methods for getting
8988 meta-attributes out of a metaclass, one of which is
90 C<get_attribute_list>. This method is called on the metaclass object.
91
92 The C<get_attribute_list> method returns a list of attribute names. You can
93 then use C<get_attribute> to get the L<Moose::Meta::Attribute> object itself.
94
95 Once you this meta-attribute object, you can call methods on it like this:
89 C<get_attribute_map>. This method is called on the metaclass object.
90
91 The C<get_attribute_map> method returns a hash reference that maps
92 attribute names to their objects. In our case, C<get_attribute_map>
93 might return something that looks like the following:
94
95 {
96 x => $attr_object_for_x,
97 y => $attr_object_for_y,
98 }
99
100 You can also get a single L<Moose::Meta::Attribute> with
101 C<get_attribute('name')>. Once you have this meta-attribute object,
102 you can call methods on it like this:
96103
97104 print $point->meta->get_attribute('x')->type_constraint;
98105 => Int
192199 sub dump {
193200 my $self = shift;
194201
195 my $meta = $self->meta;
196
197202 my $dump = '';
198203
199 for my $attribute ( map { $meta->get_attribute($_) }
200 sort $meta->get_attribute_list ) {
204 my %attributes = %{ $self->meta->get_attribute_map };
205 for my $name ( sort keys %attributes ) {
206 my $attribute = $attributes{$name};
201207
202208 if ( $attribute->isa('MyApp::Meta::Attribute::Labeled')
203209 && $attribute->has_label ) {
214220 label, we use it, otherwise we use the attribute name:
215221
216222 else {
217 $dump .= $attribute->name;
223 $dump .= $name;
218224 }
219225
220226 my $reader = $attribute->get_read_method;
3636 sub dump {
3737 my $self = shift;
3838
39 my $meta = $self->meta;
40
4139 my $dump = '';
4240
43 for my $attribute ( map { $meta->get_attribute($_) }
44 sort $meta->get_attribute_list ) {
41 my %attributes = %{ $self->meta->get_attribute_map };
42 for my $name ( sort keys %attributes ) {
43 my $attribute = $attributes{$name};
4544
4645 if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled')
4746 && $attribute->has_label ) {
4847 $dump .= $attribute->label;
4948 }
5049 else {
51 $dump .= $attribute->name;
50 $dump .= $name;
5251 }
5352
5453 my $reader = $attribute->get_read_method;
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
300300 my $exporting_package = shift;
301301 my $exporter = shift;
302302 my $exports_from = shift;
303 my $export_to_main = shift;
303304
304305 return sub {
305306
335336
336337 strict->import;
337338 warnings->import;
339
340 # we should never export to main
341 if ( $CALLER eq 'main' && !$export_to_main ) {
342 warn
343 qq{$class does not export its sugar to the 'main' package.\n};
344 return;
345 }
338346
339347 my $did_init_meta;
340348 for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) {
1212 Of course, as with any list of "best practices", these are really just
1313 opinions. Feel free to ignore us.
1414
15 =head2 C<namespace::autoclean> and immutabilize
16
17 We recommend that you remove the Moose sugar and end your Moose class
18 definitions by making your class immutable.
15 =head2 C<no Moose> and immutabilize
16
17 We recommend that you end your Moose class definitions by removing the
18 Moose sugar and making your class immutable.
1919
2020 package Person;
2121
2222 use Moose;
23 use namespace::autoclean;
2423
2524 # extends, roles, attributes, etc.
2625
2726 # methods
2827
28 no Moose;
29
2930 __PACKAGE__->meta->make_immutable;
3031
3132 1;
3233
33 The C<use namespace::autoclean> bit is simply good code hygiene, as it removes
34 imported symbols from you class's namespace at the end of your package's
35 compile cycle, including Moose keywords. Once the class has been
34 The C<no Moose> bit is simply good code hygiene, as it removes all the
35 Moose keywords from your class's namespace. Once the class has been
3636 built, these keywords are not needed needed. The C<make_immutable>
3737 call allows Moose to speed up a lot of things, most notably object
3838 construction. The trade-off is that you can no longer change the class
3939 definition.
4040
41 C<no Moose;> may be used to unimport only Moose's imported symbols.
42 L<namespace::clean> provides finer-grained control than L<namespace::autoclean>.
41 A more generic way to unimport not only L<Moose>'s exports but also
42 those from type libraries and other modules is to use
43 L<namespace::clean> or L<namespace::autoclean>.
4344
4445 =head2 Never override C<new>
4546
1010 the L</STANDARD WORKFLOW> is very simple. The general gist is: clone the Git
1111 repository, create a new topic branch, hack away, then find a committer to
1212 review your changes.
13
14 Note that this document applies to both Moose and L<Class::MOP> development.
1513
1614 =head1 NEW FEATURES
1715
227225
228226 Development releases are made without merging into the stable branch.
229227
230 =head2 Release How-To
231
232 Moose (and L<Class::MOP>) releases fall into two categories, each with their
233 own level of release preparation. A minor release is one which does not
234 include any API changes, deprecations, and so on. In that case, it is
235 sufficient to simply test the release candidate against a few different
236 different Perls. Testing should be done against at least two recent major
237 version of Perl (5.8.8 and 5.10.1, for example). If you have more versions
238 available, you are encouraged to test them all. However, we do not put a lot
239 of effort into supporting older 5.8.x releases.
240
241 For major releases which include an API change or deprecation, you should run
242 the F<cpan-stable-smolder> script from the L<moose-dev-utils
243 repository|gitmo@jules.scsys.co.uk:moose-dev-utils.git>. This script tests a
244 long list of MooseX and other Moose-using modules from CPAN. In order to run
245 this script, you must arrange to have the new version of Moose and/or
246 Class::MOP in Perl's include path. You can install the module, or fiddle with
247 the C<PERL5LIB> environment variable, whatever makes you happy.
248
249 The smolder script downloads each module from CPAN, runs its tests, and logs
250 failures and warnings to a F<cpan-stable-smolder.log> file. If there are
251 failures or warnings, please work with the authors of the modules in question
252 to fix them. If the module author simply isn't available or does not want to
253 fix the bug, it is okay to make a release.
254
255 Regardless of whether or not a new module is available, any breakages should
256 be noted in the conflicts list in the distribution's F<Makefile.PL>.
257
258 Both Class::MOP and Moose have a F<.shipit> file you can use to make sure the
259 release goes smoothly. You are strongly encouraged to use this instead of
260 doing the final release steps by hand.
261
262228 =head1 EMERGENCY BUG WORKFLOW (for immediate release)
263229
264230 Anyone can create the necessary fix by branching off of the stable branch:
4242
4343 With this definition, we can call C<< $website->host >> and it "just
4444 works". Under the hood, Moose will call C<< $website->uri->host >> for
45 you. Note that C<$website> is not automatically passed to the C<host>
46 method; the invocant is C<< $website->uri >>.
45 you.
4746
4847 We can also define a mapping as a hash reference. This allows you to
4948 rename methods as part of the mapping:
1414 feature. If you encounter a problem and have a solution but don't see
1515 it documented here, or think we missed an important feature, please
1616 send us a patch.
17
18 =head1 0.93
19
20 =over 4
21
22 =item Calling $object->new() is no longer deprecated
23
24 We decided to undeprecate this. Now it just works.
25
26 =back
2717
2818 =head1 0.90
2919
7262 this may cause issues should be helpful. Metaclasses (classes that inherit
7363 from L<Class::MOP::Object>) are currently exempt from this check, since at the
7464 moment we aren't very consistent about which metaclasses we immutabilize.
75
76 =item C<enum> and C<duck_type> now take arrayrefs for all forms
77
78 Previously, calling these functions with a list would take the first element of
79 the list as the type constraint name, and use the remainder as the enum values
80 or method names. This makes the interface inconsistent with the anon-type forms
81 of these functions (which must take an arrayref), and a free-form list where
82 the first value is sometimes special is hard to validate (and harder to give
83 reasonable error messages for). These functions have been changed to take
84 arrayrefs in all their forms - so, C<< enum 'My::Type' => [qw(foo bar)] >> is
85 now the preferred way to create an enum type constraint. The old syntax still
86 works for now, but it will hopefully be deprecated and removed in a future
87 release.
8865
8966 =back
9067
3838 Undef
3939 Defined
4040 Value
41 Num
42 Int
4143 Str
42 Num
43 Int
4444 ClassName
4545 RoleName
4646 Ref
33 use List::Util;
44 use List::MoreUtils;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
2525 my ( $attr, $reader, $writer ) = @_;
2626 return sub {
2727 my ( $instance, $predicate ) = @_;
28 List::Util::first { $predicate->() } @{ $reader->($instance) };
28 &List::Util::first($predicate, @{ $reader->($instance) });
2929 };
3030 }
3131
11 package Moose::Meta::Attribute::Native::MethodProvider::Bool;
22 use Moose::Role;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
00 package Moose::Meta::Attribute::Native::MethodProvider::Code;
11 use Moose::Role;
22
3 our $VERSION = '0.93';
3 our $VERSION = '0.92';
44 $VERSION = eval $VERSION;
55 our $AUTHORITY = 'cpan:STEVAN';
66
77 sub execute : method {
88 my ( $attr, $reader, $writer ) = @_;
9 return sub { my ($self, @args) = @_; $reader->($self)->(@args) };
9 return sub { $reader->(@_)->(@_) };
1010 }
1111
1212 no Moose::Role;
11 package Moose::Meta::Attribute::Native::MethodProvider::Counter;
22 use Moose::Role;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
00 package Moose::Meta::Attribute::Native::MethodProvider::Hash;
11 use Moose::Role;
22
3 our $VERSION = '0.93';
3 our $VERSION = '0.92';
44 $VERSION = eval $VERSION;
55 our $AUTHORITY = 'cpan:STEVAN';
66
00 package Moose::Meta::Attribute::Native::MethodProvider::String;
11 use Moose::Role;
22
3 our $VERSION = '0.93';
3 our $VERSION = '0.92';
44 $VERSION = eval $VERSION;
55 our $AUTHORITY = 'cpan:STEVAN';
66
11 package Moose::Meta::Attribute::Native::Trait::Array;
22 use Moose::Role;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
11 use Moose::Role;
22 use Moose::Meta::Attribute::Native::MethodProvider::Bool;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
11 use Moose::Role;
22 use Moose::Meta::Attribute::Native::MethodProvider::Code;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
11 package Moose::Meta::Attribute::Native::Trait::Counter;
22 use Moose::Role;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
11 package Moose::Meta::Attribute::Native::Trait::Hash;
22 use Moose::Role;
33
4 our $VERSION = '0.93';
4 our $VERSION = '0.92';
55 $VERSION = eval $VERSION;
66 our $AUTHORITY = 'cpan:STEVAN';
77
00 package Moose::Meta::Attribute::Native::Trait::Number;
11 use Moose::Role;
22
3 our $VERSION = '0.93';
3 our $VERSION = '0.92';
44 $VERSION = eval $VERSION;
55 our $AUTHORITY = 'cpan:STEVAN';
66
00 package Moose::Meta::Attribute::Native::Trait::String;
11 use Moose::Role;
22
3 our $VERSION = '0.93';
3 our $VERSION = '0.92';
44 $VERSION = eval $VERSION;
55 our $AUTHORITY = 'cpan:STEVAN';
66
22 use Moose::Role;
33 use Moose::Util::TypeConstraints;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
145145 exception. If you find a bug please either email me, or add the bug
146146 to cpan-RT.
147147
148 =head1 SEE ALSO
149
150 Documentation for Moose native traits starts at L<Moose::Meta::Attribute Native>
151
152148 =head1 AUTHORS
153149
154150 Yuval Kogman
00 package Moose::Meta::Attribute::Native;
11
2 our $VERSION = '0.93';
2 our $VERSION = '0.92';
33 $VERSION = eval $VERSION;
44 our $AUTHORITY = 'cpan:STEVAN';
55
44 use warnings;
55
66 use Scalar::Util 'blessed', 'weaken';
7 use List::MoreUtils 'any';
8 use Try::Tiny;
97 use overload ();
108
11 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1210 our $AUTHORITY = 'cpan:STEVAN';
1311
1412 use Moose::Meta::Method::Accessor;
5957 # for metatrait aliases.
6058 sub does {
6159 my ($self, $role_name) = @_;
62 my $name = try {
60 my $name = eval {
6361 Moose::Util::resolve_metatrait_alias(Attribute => $role_name)
6462 };
6563 return 0 if !defined($name); # failed to load class
319317
320318 if (exists $options->{isa}) {
321319 if (exists $options->{does}) {
322 if (try { $options->{isa}->can('does') }) {
320 if (eval { $options->{isa}->can('does') }) {
323321 ($options->{isa}->does($options->{does}))
324322 || $class->throw_error("Cannot have an isa option and a does option if the isa does not do the does on attribute ($name)", data => $options);
325323 }
657655 my %handles = $self->_canonicalize_handles;
658656 my $associated_class = $self->associated_class;
659657 foreach my $handle (keys %handles) {
660 next unless any { $handle eq $_ }
661 map { $_->name }
662 @{ $self->associated_methods };
663658 $self->associated_class->remove_method($handle);
664659 }
665660 }
744739 sub _make_delegation_method {
745740 my ( $self, $handle_name, $method_to_call ) = @_;
746741
742 my $method_body;
743
744 $method_body = $method_to_call
745 if 'CODE' eq ref($method_to_call);
746
747747 my @curried_arguments;
748748
749749 ($method_to_call, @curried_arguments) = @$method_to_call
44
55 use Class::MOP;
66
7 our $VERSION = '0.93';
7 our $VERSION = '0.92';
88 $VERSION = eval $VERSION;
99 our $AUTHORITY = 'cpan:STEVAN';
1010
1010 use List::MoreUtils qw( any all uniq first_index );
1111 use Scalar::Util 'weaken', 'blessed';
1212
13 our $VERSION = '0.93';
13 our $VERSION = '0.92';
1414 $VERSION = eval $VERSION;
1515 our $AUTHORITY = 'cpan:STEVAN';
1616
33 use strict;
44 use warnings;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
33 use strict;
44 use warnings;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
55
66 use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 our $AUTHORITY = 'cpan:STEVAN';
1010
1111 use base 'Moose::Meta::Method',
5555 # the author, after all, nothing is free)
5656 my $source = 'sub {';
5757 $source .= "\n" . 'my $_instance = shift;';
58
59 $source .= "\n" . q{Carp::cluck 'Calling new() on an instance is deprecated,'
60 . ' please use (blessed $obj)->new' if Scalar::Util::blessed($_instance);};
5861
5962 $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;';
6063
66 use Carp 'confess';
77 use Scalar::Util 'blessed', 'weaken';
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
103103 object => $instance
104104 );
105105 }
106 unshift @_, @{ $self->curried_arguments };
107 $proxy->$method_to_call(@_);
106 my @args = (@{ $self->curried_arguments }, @_);
107 $proxy->$method_to_call(@args);
108108 };
109109 }
110110
77 use Scalar::Util 'blessed', 'weaken';
88 use Try::Tiny ();
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
22 use strict;
33 use warnings;
44
5 our $VERSION = '0.93';
5 our $VERSION = '0.92';
66 $VERSION = eval $VERSION;
77 our $AUTHORITY = 'cpan:STEVAN';
88
77
88 use Moose::Meta::Role::Composite;
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
66 use Moose::Util 'english_list';
77 use Scalar::Util 'weaken', 'blessed';
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
55
66 use Scalar::Util 'blessed';
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
55
66 use Scalar::Util 'blessed';
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
33 use warnings;
44 use metaclass;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
55
66 use Scalar::Util 'blessed';
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
77
88 use base qw(Moose::Meta::Role::Method::Required);
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
99
1010 use base qw(Class::MOP::Object);
1111
12 our $VERSION = '0.93';
12 our $VERSION = '0.92';
1313 $VERSION = eval $VERSION;
1414 our $AUTHORITY = 'cpan:STEVAN';
1515
33 use strict;
44 use warnings;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
66
77 use Scalar::Util 'blessed';
88 use Carp 'confess';
9 use Sub::Name 'subname';
910 use Devel::GlobalDestruction 'in_global_destruction';
1011
11 our $VERSION = '0.93';
12 our $VERSION = '0.92';
1213 $VERSION = eval $VERSION;
1314 our $AUTHORITY = 'cpan:STEVAN';
1415
7071 }
7172 },
7273 {
73 name => '_attribute_map',
74 attr_reader => '_attribute_map',
74 name => 'attribute_map',
75 attr_reader => 'get_attribute_map',
7576 methods => {
7677 get => 'get_attribute',
7778 get_keys => 'get_attribute_list',
180181 else {
181182 $attr_desc = { @_ };
182183 }
183 $self->_attribute_map->{$name} = $attr_desc;
184 $self->get_attribute_map->{$name} = $attr_desc;
184185 }
185186
186187 sub add_required_methods {
565566 #
566567 # has 'attribute_map' => (
567568 # metaclass => 'Hash',
568 # reader => '_attribute_map',
569 # reader => 'get_attribute_map',
569570 # isa => 'HashRef[Str]',
570571 # provides => {
571572 # # 'set' => 'add_attribute' # has some special crap in it
817818
818819 =item B<< $metarole->has_attribute($attribute_name) >>
819820
821 =item B<< $metarole->get_attribute_map >>
822
820823 =item B<< $metarole->get_attribute_list >>
821824
822825 =item B<< $metarole->add_attribute($name, %options) >>
66
77 use Scalar::Util 'blessed';
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
77 use Moose::Meta::Attribute;
88 use Moose::Util::TypeConstraints ();
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
66 use Scalar::Util 'blessed';
77 use Moose::Util::TypeConstraints ();
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
99
1010 use Moose::Util::TypeConstraints ();
1111
12 our $VERSION = '0.93';
12 our $VERSION = '0.92';
1313 $VERSION = eval $VERSION;
1414 our $AUTHORITY = 'cpan:STEVAN';
1515
55
66 use Moose::Util::TypeConstraints ();
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
33 use warnings;
44 use metaclass;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
77 use Moose::Util::TypeConstraints;
88 use Moose::Meta::TypeConstraint::Parameterizable;
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
66
77 use Scalar::Util 'blessed';
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
66 use Scalar::Util 'blessed';
77 use Moose::Util::TypeConstraints ();
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
66
77 use Moose::Meta::TypeCoercion::Union;
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
1212
1313 use base qw(Class::MOP::Object);
1414
15 our $VERSION = '0.93';
15 our $VERSION = '0.92';
1616 $VERSION = eval $VERSION;
1717 our $AUTHORITY = 'cpan:STEVAN';
1818
1111 use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
1212 use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
1313
14 our $VERSION = '0.93';
14 our $VERSION = '0.92';
1515 $VERSION = eval $VERSION;
1616 our $AUTHORITY = 'cpan:STEVAN';
1717
1818 sub new {
1919 my $class = shift;
20
21 Carp::cluck 'Calling new() on an instance is deprecated,'
22 . ' please use (blessed $obj)->new' if Scalar::Util::blessed($class);
2023
2124 my $params = $class->BUILDARGS(@_);
2225
117120 my ($self, $role_name) = @_;
118121 my $meta = Class::MOP::class_of($self);
119122 (defined $role_name)
120 || $meta->throw_error("You must supply a role name to does()");
123 || $meta->throw_error("You much supply a role name to does()");
121124 foreach my $class ($meta->class_precedence_list) {
122125 my $m = $meta->initialize($class);
123126 return 1
66
77 use Sub::Exporter;
88
9 our $VERSION = '0.93';
9 our $VERSION = '0.92';
1010 $VERSION = eval $VERSION;
1111 our $AUTHORITY = 'cpan:STEVAN';
1212
33 use warnings;
44 use Scalar::Util 'blessed';
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
55 use Class::MOP;
66 use Scalar::Util 'blessed', 'looks_like_number';
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
1313
1414 sub Ref { ref($_[0]) }
1515
16 sub Str { defined($_[0]) && ref(\$_[0]) eq 'SCALAR' }
16 sub Str { defined($_[0]) && !ref($_[0]) }
1717
1818 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
1919
55 use Scalar::Util qw( blessed reftype );
66 use Moose::Exporter;
77
8 our $VERSION = '0.93';
8 our $VERSION = '0.92';
99 $VERSION = eval $VERSION;
1010 our $AUTHORITY = 'cpan:STEVAN';
1111
364364 if ( ref $type_name eq 'ARRAY' && !@methods ) {
365365 @methods = @$type_name;
366366 $type_name = undef;
367 }
368 if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) {
369 @methods = @{ $methods[0] };
370367 }
371368
372369 register_type_constraint(
414411 @values = @$type_name;
415412 $type_name = undef;
416413 }
417 if ( @values == 1 && ref $values[0] eq 'ARRAY' ) {
418 @values = @{ $values[0] };
419 }
420414 ( scalar @values >= 2 )
421415 || __PACKAGE__->_throw_error(
422416 "You must have at least two values to enumerate through");
661655 subtype 'Ref' => as 'Defined' => where { ref($_) } =>
662656 optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Ref;
663657
664 subtype 'Str' => as 'Value' => where { ref(\$_) eq 'SCALAR' } =>
658 subtype 'Str' => as 'Value' => where {1} =>
665659 optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Str;
666660
667661 subtype 'Num' => as 'Str' =>
887881 Undef
888882 Defined
889883 Value
884 Num
885 Int
890886 Str
891 Num
892 Int
893887 ClassName
894888 RoleName
895889 Ref
10311025 Creates a type constraint for either C<undef> or something of the
10321026 given type.
10331027
1034 =item B<duck_type ($name, \@methods)>
1028 =item B<duck_type ($name, @methods)>
10351029
10361030 This will create a subtype of Object and test to make sure the value
1037 C<can()> do the methods in C<\@methods>.
1031 C<can()> do the methods in C<@methods>.
10381032
10391033 This is intended as an easy way to accept non-Moose objects that
10401034 provide a certain interface. If you're using Moose classes, we
10421036
10431037 =item B<duck_type (\@methods)>
10441038
1045 If passed an ARRAY reference as the only parameter instead of the
1046 C<$name>, C<\@methods> pair, this will create an unnamed duck type.
1047 This can be used in an attribute definition like so:
1039 If passed an ARRAY reference instead of the C<$name>, C<@methods>
1040 pair, this will create an unnamed duck type. This can be used in an
1041 attribute definition like so:
10481042
10491043 has 'cache' => (
10501044 is => 'ro',
10511045 isa => duck_type( [qw( get_set )] ),
10521046 );
10531047
1054 =item B<enum ($name, \@values)>
1048 =item B<enum ($name, @values)>
10551049
10561050 This will create a basic subtype for a given set of strings.
10571051 The resulting constraint will be a subtype of C<Str> and
1058 will match any of the items in C<\@values>. It is case sensitive.
1052 will match any of the items in C<@values>. It is case sensitive.
10591053 See the L<SYNOPSIS> for a simple example.
10601054
10611055 B<NOTE:> This is not a true proper enum type, it is simply
10631057
10641058 =item B<enum (\@values)>
10651059
1066 If passed an ARRAY reference as the only parameter instead of the
1067 C<$name>, C<\@values> pair, this will create an unnamed enum. This
1068 can then be used in an attribute definition like so:
1060 If passed an ARRAY reference instead of the C<$name>, C<@values> pair,
1061 this will create an unnamed enum. This can then be used in an attribute
1062 definition like so:
10691063
10701064 has 'sort_order' => (
10711065 is => 'ro',
77 use Scalar::Util 'blessed';
88 use Class::MOP 0.60;
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
33
44 use 5.008;
55
6 our $VERSION = '0.93';
6 our $VERSION = '0.92';
77 $VERSION = eval $VERSION;
88 our $AUTHORITY = 'cpan:STEVAN';
99
77
88 use Moose::Util 'does_role', 'find_meta';
99
10 our $VERSION = '0.93';
10 our $VERSION = '0.92';
1111 $VERSION = eval $VERSION;
1212 our $AUTHORITY = 'cpan:STEVAN';
1313
44
55 use Class::MOP;
66
7 our $VERSION = '0.93';
7 our $VERSION = '0.92';
88 $VERSION = eval $VERSION;
99 our $AUTHORITY = 'cpan:STEVAN';
1010
4040 sub dump {
4141 my $self = shift;
4242
43 my $meta = $self->meta;
44
4543 my $dump = '';
4644
47 for my $attribute ( map { $meta->get_attribute($_) }
48 sort $meta->get_attribute_list ) {
45 my %attributes = %{ $self->meta->get_attribute_map };
46 for my $name ( sort keys %attributes ) {
47 my $attribute = $attributes{$name};
4948
5049 if ( $attribute->isa('MyApp::Meta::Attribute::Labeled')
5150 && $attribute->has_label ) {
5251 $dump .= $attribute->label;
5352 }
5453 else {
55 $dump .= $attribute->name;
54 $dump .= $name;
5655 }
5756
5857 my $reader = $attribute->get_read_method;
3939 sub dump {
4040 my $self = shift;
4141
42 my $meta = $self->meta;
43
4442 my $dump = '';
4543
46 for my $attribute ( map { $meta->get_attribute($_) }
47 sort $meta->get_attribute_list ) {
44 my %attributes = %{ $self->meta->get_attribute_map };
45 for my $name ( sort keys %attributes ) {
46 my $attribute = $attributes{$name};
4847
4948 if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled')
5049 && $attribute->has_label ) {
5150 $dump .= $attribute->label;
5251 }
5352 else {
54 $dump .= $attribute->name;
53 $dump .= $name;
5554 }
5655
5756 my $reader = $attribute->get_read_method;
22 use strict;
33 use warnings;
44
5 use Test::More tests => 29;
5 use Test::More tests => 30;
66 use Test::Exception;
77
88
2121
2222 dies_ok {
2323 Foo->meta->has_method()
24 } '... has_method requires an arg';
25
26 dies_ok {
27 Foo->meta->has_method('')
2428 } '... has_method requires an arg';
2529
2630 can_ok('Foo', 'does');
44
55 use lib 't/lib', 'lib';
66
7 use Test::More tests => 4;
8 use Test::Exception;
7 use Test::More tests => 5;
98
109
1110
1211 {
13
1412 package Bar;
1513 use Moose;
1614
17 ::lives_ok { extends 'Foo' } 'loaded Foo superclass correctly';
15 eval { extends 'Foo'; };
16 ::ok(!$@, '... loaded Foo superclass correctly');
1817 }
1918
2019 {
21
2220 package Baz;
2321 use Moose;
2422
25 ::lives_ok { extends 'Bar' } 'loaded (inline) Bar superclass correctly';
23 eval { extends 'Bar'; };
24 ::ok(!$@, '... loaded (inline) Bar superclass correctly');
2625 }
2726
2827 {
29
3028 package Foo::Bar;
3129 use Moose;
3230
33 ::lives_ok { extends 'Foo', 'Bar' }
34 'loaded Foo and (inline) Bar superclass correctly';
31 eval { extends 'Foo', 'Bar'; };
32 ::ok(!$@, '... loaded Foo and (inline) Bar superclass correctly');
3533 }
3634
3735 {
38
3936 package Bling;
4037 use Moose;
4138
42 ::throws_ok { extends 'No::Class' }
43 qr{Can't locate No/Class\.pm in \@INC},
44 'correct error when superclass could not be found';
39 eval { extends 'No::Class'; };
40 ::ok($@, '... could not find the superclass (as expected)');
41 ::like($@, qr/^Could not load class \(No\:\:Class\) because \:/, '... and got the error we expected');
4542 }
4643
22 use strict;
33 use warnings;
44
5 use Test::More tests => 4;
6 use Test::Exception;
5 use Test::More;
6 BEGIN {
7 eval "use Test::Output;";
8 plan skip_all => "Test::Output is required for this test" if $@;
9 plan tests => 2;
10 }
711
8 lives_ok {
9 eval 'use Moose';
10 } "export to main";
12 stderr_like( sub { package main; eval 'use Moose' },
13 qr/\QMoose does not export its sugar to the 'main' package/,
14 'Moose warns when loaded from the main package' );
1115
12 isa_ok( main->meta, "Moose::Meta::Class" );
13
14 isa_ok( main->new, "main");
15 isa_ok( main->new, "Moose::Object" );
16
16 stderr_like( sub { package main; eval 'use Moose::Role' },
17 qr/\QMoose::Role does not export its sugar to the 'main' package/,
18 'Moose::Role warns when loaded from the main package' );
1717 throws_ok { Foo->new(undef) } qr/^\QSingle parameters to new() must be a HASH ref/,
1818 'A single non-hashref arg to a constructor throws an error';
1919
20 throws_ok { Foo->does() } qr/^\QYou must supply a role name to does()/,
20 throws_ok { Foo->does() } qr/^\QYou much supply a role name to does()/,
2121 'Cannot call does() without a role name';
0 use strict;
1 use warnings;
2
3 use Test::More;
4 use Test::Exception;
5 BEGIN {
6 eval "use Test::Output;";
7 plan skip_all => "Test::Output is required for this test" if $@;
8 plan tests => 2;
9 }
10
11 {
12 package Foo;
13 use Moose;
14 }
15
16 {
17 my $foo = Foo->new();
18 stderr_like { $foo->new() }
19 qr/\QCalling new() on an instance is deprecated/,
20 '$object->new() is deprecated';
21
22 Foo->meta->make_immutable, redo
23 if Foo->meta->is_mutable;
24 }
22 use strict;
33 use warnings;
44
5 use Test::More tests => 48;
5 use Test::More tests => 39;
66 use Test::Exception;
77
88 =pod
7575
7676 sub child_g_method_1 { "g1" }
7777
78 package ChildH;
79 use Moose;
80
81 sub child_h_method_1 { "h1" }
82 sub parent_method_1 { "child_parent_1" }
83
84 package ChildI;
85 use Moose;
86
87 sub child_i_method_1 { "i1" }
88 sub parent_method_1 { "child_parent_1" }
89
9078 package Parent;
9179 use Moose;
92
93 sub parent_method_1 { "parent_1" }
94 ::can_ok('Parent', 'parent_method_1');
9580
9681 ::dies_ok {
9782 has child_a => (
180165 handles => ["child_g_method_1"],
181166 );
182167 } "can delegate to object even without explicit reader";
183
184 ::can_ok('Parent', 'parent_method_1');
185 ::dies_ok {
186 has child_h => (
187 isa => "ChildH",
188 is => "ro",
189 default => sub { ChildH->new },
190 handles => sub { map { $_, $_ } $_[1]->get_all_method_names },
191 );
192 } "Can't override exisiting class method in delegate";
193 ::can_ok('Parent', 'parent_method_1');
194
195 ::lives_ok {
196 has child_i => (
197 isa => "ChildI",
198 is => "ro",
199 default => sub { ChildI->new },
200 handles => sub {
201 map { $_, $_ } grep { !/^parent_method_1|meta$/ }
202 $_[1]->get_all_method_names;
203 },
204 );
205 } "Test handles code ref for skipping predefined methods";
206
207168
208169 sub parent_method { "p" }
209170 }
217178 isa_ok( $p->child_d, "ChildD" );
218179 isa_ok( $p->child_e, "ChildE" );
219180 isa_ok( $p->child_f, "ChildF" );
220 isa_ok( $p->child_i, "ChildI" );
221181
222182 ok(!$p->can('child_g'), '... no child_g accessor defined');
223 ok(!$p->can('child_h'), '... no child_h accessor defined');
224183
225184
226185 is( $p->parent_method, "p", "parent method" );
255214
256215 can_ok( $p, "child_g_method_1" );
257216 is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" );
258
259 can_ok( $p, "child_i_method_1" );
260 is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" );
+0
-39
t/020_attributes/032_delegation_arg_aliasing.t less more
0 #!/usr/bin/env perl
1 use strict;
2 use warnings;
3 use Test::More tests => 3;
4
5 {
6 package Foo;
7 use Moose;
8
9 sub aliased {
10 my $self = shift;
11 $_[1] = $_[0];
12 }
13 }
14
15 {
16 package HasFoo;
17 use Moose;
18
19 has foo => (
20 is => 'ro',
21 isa => 'Foo',
22 handles => {
23 foo_aliased => 'aliased',
24 foo_aliased_curried => ['aliased', 'bar'],
25 }
26 );
27 }
28
29 my $hasfoo = HasFoo->new(foo => Foo->new);
30 my $x;
31 $hasfoo->foo->aliased('foo', $x);
32 is($x, 'foo', "direct aliasing works");
33 undef $x;
34 $hasfoo->foo_aliased('foo', $x);
35 is($x, 'foo', "delegated aliasing works");
36 undef $x;
37 $hasfoo->foo_aliased_curried($x);
38 is($x, 'bar', "delegated aliasing with currying works");
22 use strict;
33 use warnings;
44
5 use Test::More tests => 297;
5 use Test::More tests => 277;
66 use Test::Exception;
77
88 use Scalar::Util ();
1414 my $SCALAR_REF = \(my $var);
1515
1616 no warnings 'once'; # << I *hates* that warning ...
17 my $GLOB = *GLOB_REF;
18 my $GLOB_REF = \$GLOB;
17 my $GLOB_REF = \*GLOB_REF;
1918
2019 my $fh;
2120 open($fh, '<', $0) || die "Could not open $0 for the test";
3231 ok(defined Any({}), '... Any accepts anything');
3332 ok(defined Any(sub {}), '... Any accepts anything');
3433 ok(defined Any($SCALAR_REF), '... Any accepts anything');
35 ok(defined Any($GLOB), '... Any accepts anything');
3634 ok(defined Any($GLOB_REF), '... Any accepts anything');
3735 ok(defined Any($fh), '... Any accepts anything');
3836 ok(defined Any(qr/../), '... Any accepts anything');
4745 ok(defined Item({}), '... Item is the base type, so accepts anything');
4846 ok(defined Item(sub {}), '... Item is the base type, so accepts anything');
4947 ok(defined Item($SCALAR_REF), '... Item is the base type, so accepts anything');
50 ok(defined Item($GLOB), '... Item is the base type, so accepts anything');
5148 ok(defined Item($GLOB_REF), '... Item is the base type, so accepts anything');
5249 ok(defined Item($fh), '... Item is the base type, so accepts anything');
5350 ok(defined Item(qr/../), '... Item is the base type, so accepts anything');
6259 ok(defined Defined({}), '... Defined accepts anything which is defined');
6360 ok(defined Defined(sub {}), '... Defined accepts anything which is defined');
6461 ok(defined Defined($SCALAR_REF), '... Defined accepts anything which is defined');
65 ok(defined Defined($GLOB), '... Defined accepts anything which is defined');
6662 ok(defined Defined($GLOB_REF), '... Defined accepts anything which is defined');
6763 ok(defined Defined($fh), '... Defined accepts anything which is defined');
6864 ok(defined Defined(qr/../), '... Defined accepts anything which is defined');
7773 ok(!defined Undef({}), '... Undef accepts anything which is not defined');
7874 ok(!defined Undef(sub {}), '... Undef accepts anything which is not defined');
7975 ok(!defined Undef($SCALAR_REF), '... Undef accepts anything which is not defined');
80 ok(!defined Undef($GLOB), '... Undef accepts anything which is not defined');
8176 ok(!defined Undef($GLOB_REF), '... Undef accepts anything which is not defined');
8277 ok(!defined Undef($fh), '... Undef accepts anything which is not defined');
8378 ok(!defined Undef(qr/../), '... Undef accepts anything which is not defined');
9388 ok(!defined Bool({}), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
9489 ok(!defined Bool(sub {}), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
9590 ok(!defined Bool($SCALAR_REF), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
96 ok(!defined Bool($GLOB), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
9791 ok(!defined Bool($GLOB_REF), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
9892 ok(!defined Bool($fh), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
9993 ok(!defined Bool(qr/../), '... Bool rejects anything which is not a 1 or 0 or "" or undef');
108102 ok(!defined Value({}), '... Value rejects anything which is not a Value');
109103 ok(!defined Value(sub {}), '... Value rejects anything which is not a Value');
110104 ok(!defined Value($SCALAR_REF), '... Value rejects anything which is not a Value');
111 ok(defined Value($GLOB), '... Value accepts anything which is not a Ref');
112105 ok(!defined Value($GLOB_REF), '... Value rejects anything which is not a Value');
113106 ok(!defined Value($fh), '... Value rejects anything which is not a Value');
114107 ok(!defined Value(qr/../), '... Value rejects anything which is not a Value');
123116 ok(defined Ref({}), '... Ref rejects anything which is not a Ref');
124117 ok(defined Ref(sub {}), '... Ref rejects anything which is not a Ref');
125118 ok(defined Ref($SCALAR_REF), '... Ref rejects anything which is not a Ref');
126 ok(!defined Ref($GLOB), '... Ref accepts anything which is not a Value');
127119 ok(defined Ref($GLOB_REF), '... Ref rejects anything which is not a Ref');
128120 ok(defined Ref($fh), '... Ref rejects anything which is not a Ref');
129121 ok(defined Ref(qr/../), '... Ref rejects anything which is not a Ref');
140132 ok(!defined Int({}), '... Int rejects anything which is not a Int');
141133 ok(!defined Int(sub {}), '... Int rejects anything which is not a Int');
142134 ok(!defined Int($SCALAR_REF), '... Int rejects anything which is not a Int');
143 ok(!defined Int($GLOB), '... Int rejects anything which is not a Int');
144135 ok(!defined Int($GLOB_REF), '... Int rejects anything which is not a Int');
145136 ok(!defined Int($fh), '... Int rejects anything which is not a Int');
146137 ok(!defined Int(qr/../), '... Int rejects anything which is not a Int');
157148 ok(!defined Num({}), '... Num rejects anything which is not a Num');
158149 ok(!defined Num(sub {}), '... Num rejects anything which is not a Num');
159150 ok(!defined Num($SCALAR_REF), '... Num rejects anything which is not a Num');
160 ok(!defined Num($GLOB), '... Num rejects anything which is not a Num');
161151 ok(!defined Num($GLOB_REF), '... Num rejects anything which is not a Num');
162152 ok(!defined Num($fh), '... Num rejects anything which is not a Num');
163153 ok(!defined Num(qr/../), '... Num rejects anything which is not a Num');
173163 ok(!defined Str(sub {}), '... Str rejects anything which is not a Str');
174164 ok(!defined Str($SCALAR_REF), '... Str rejects anything which is not a Str');
175165 ok(!defined Str($fh), '... Str rejects anything which is not a Str');
176 ok(!defined Str($GLOB), '... Str rejects anything which is not a Str');
177166 ok(!defined Str($GLOB_REF), '... Str rejects anything which is not a Str');
178167 ok(!defined Str(qr/../), '... Str rejects anything which is not a Str');
179168 ok(!defined Str(bless {}, 'Foo'), '... Str rejects anything which is not a Str');
187176 ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef');
188177 ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef');
189178 ok(defined ScalarRef($SCALAR_REF), '... ScalarRef accepts anything which is a ScalarRef');
190 ok(!defined ScalarRef($GLOB), '... ScalarRef rejects anything which is not a ScalarRef');
191179 ok(!defined ScalarRef($GLOB_REF), '... ScalarRef rejects anything which is not a ScalarRef');
192180 ok(!defined ScalarRef($fh), '... ScalarRef rejects anything which is not a ScalarRef');
193181 ok(!defined ScalarRef(qr/../), '... ScalarRef rejects anything which is not a ScalarRef');
202190 ok(!defined ArrayRef({}), '... ArrayRef rejects anything which is not a ArrayRef');
203191 ok(!defined ArrayRef(sub {}), '... ArrayRef rejects anything which is not a ArrayRef');
204192 ok(!defined ArrayRef($SCALAR_REF), '... ArrayRef rejects anything which is not a ArrayRef');
205 ok(!defined ArrayRef($GLOB), '... ArrayRef rejects anything which is not a ArrayRef');
206193 ok(!defined ArrayRef($GLOB_REF), '... ArrayRef rejects anything which is not a ArrayRef');
207194 ok(!defined ArrayRef($fh), '... ArrayRef rejects anything which is not a ArrayRef');
208195 ok(!defined ArrayRef(qr/../), '... ArrayRef rejects anything which is not a ArrayRef');
217204 ok(defined HashRef({}), '... HashRef accepts anything which is a HashRef');
218205 ok(!defined HashRef(sub {}), '... HashRef rejects anything which is not a HashRef');
219206 ok(!defined HashRef($SCALAR_REF), '... HashRef rejects anything which is not a HashRef');
220 ok(!defined HashRef($GLOB), '... HashRef rejects anything which is not a HashRef');
221207 ok(!defined HashRef($GLOB_REF), '... HashRef rejects anything which is not a HashRef');
222208 ok(!defined HashRef($fh), '... HashRef rejects anything which is not a HashRef');
223209 ok(!defined HashRef(qr/../), '... HashRef rejects anything which is not a HashRef');
232218 ok(!defined CodeRef({}), '... CodeRef rejects anything which is not a CodeRef');
233219 ok(defined CodeRef(sub {}), '... CodeRef accepts anything which is a CodeRef');
234220 ok(!defined CodeRef($SCALAR_REF), '... CodeRef rejects anything which is not a CodeRef');
235 ok(!defined CodeRef($GLOB), '... CodeRef rejects anything which is not a CodeRef');
236221 ok(!defined CodeRef($GLOB_REF), '... CodeRef rejects anything which is not a CodeRef');
237222 ok(!defined CodeRef($fh), '... CodeRef rejects anything which is not a CodeRef');
238223 ok(!defined CodeRef(qr/../), '... CodeRef rejects anything which is not a CodeRef');
247232 ok(!defined RegexpRef({}), '... RegexpRef rejects anything which is not a RegexpRef');
248233 ok(!defined RegexpRef(sub {}), '... RegexpRef rejects anything which is not a RegexpRef');
249234 ok(!defined RegexpRef($SCALAR_REF), '... RegexpRef rejects anything which is not a RegexpRef');
250 ok(!defined RegexpRef($GLOB), '... RegexpRef rejects anything which is not a RegexpRef');
251235 ok(!defined RegexpRef($GLOB_REF), '... RegexpRef rejects anything which is not a RegexpRef');
252236 ok(!defined RegexpRef($fh), '... RegexpRef rejects anything which is not a RegexpRef');
253237 ok(defined RegexpRef(qr/../), '... RegexpRef accepts anything which is a RegexpRef');
262246 ok(!defined GlobRef({}), '... GlobRef rejects anything which is not a GlobRef');
263247 ok(!defined GlobRef(sub {}), '... GlobRef rejects anything which is not a GlobRef');
264248 ok(!defined GlobRef($SCALAR_REF), '... GlobRef rejects anything which is not a GlobRef');
265 ok(!defined GlobRef($GLOB), '... GlobRef rejects anything which is not a GlobRef');
266249 ok(defined GlobRef($GLOB_REF), '... GlobRef accepts anything which is a GlobRef');
267250 ok(defined GlobRef($fh), '... GlobRef accepts anything which is a GlobRef');
268251 ok(!defined GlobRef($fh_obj), '... GlobRef rejects anything which is not a GlobRef');
278261 ok(!defined FileHandle({}), '... FileHandle rejects anything which is not a FileHandle');
279262 ok(!defined FileHandle(sub {}), '... FileHandle rejects anything which is not a FileHandle');
280263 ok(!defined FileHandle($SCALAR_REF), '... FileHandle rejects anything which is not a FileHandle');
281 ok(!defined FileHandle($GLOB), '... FileHandle rejects anything which is not a FileHandle');
282264 ok(!defined FileHandle($GLOB_REF), '... FileHandle rejects anything which is not a FileHandle');
283265 ok(defined FileHandle($fh), '... FileHandle accepts anything which is a FileHandle');
284266 ok(defined FileHandle($fh_obj), '... FileHandle accepts anything which is a FileHandle');
294276 ok(!defined Object({}), '... Object rejects anything which is not blessed');
295277 ok(!defined Object(sub {}), '... Object rejects anything which is not blessed');
296278 ok(!defined Object($SCALAR_REF), '... Object rejects anything which is not blessed');
297 ok(!defined Object($GLOB), '... Object rejects anything which is not blessed');
298279 ok(!defined Object($GLOB_REF), '... Object rejects anything which is not blessed');
299280 ok(!defined Object($fh), '... Object rejects anything which is not blessed');
300281 ok(!defined Object(qr/../), '... Object rejects anything which is not blessed');
318299 ok(!defined ClassName(sub {}), '... ClassName rejects anything which is not a ClassName');
319300 ok(!defined ClassName($SCALAR_REF), '... ClassName rejects anything which is not a ClassName');
320301 ok(!defined ClassName($fh), '... ClassName rejects anything which is not a ClassName');
321 ok(!defined ClassName($GLOB), '... ClassName rejects anything which is not a ClassName');
322302 ok(!defined ClassName($GLOB_REF), '... ClassName rejects anything which is not a ClassName');
323303 ok(!defined ClassName(qr/../), '... ClassName rejects anything which is not a ClassName');
324304 ok(!defined ClassName(bless {}, 'Foo'), '... ClassName rejects anything which is not a ClassName');
344324 ok(!defined RoleName(sub {}), '... Rolename rejects anything which is not a RoleName');
345325 ok(!defined RoleName($SCALAR_REF), '... Rolename rejects anything which is not a RoleName');
346326 ok(!defined RoleName($fh), '... Rolename rejects anything which is not a RoleName');
347 ok(!defined RoleName($GLOB), '... Rolename rejects anything which is not a RoleName');
348327 ok(!defined RoleName($GLOB_REF), '... Rolename rejects anything which is not a RoleName');
349328 ok(!defined RoleName(qr/../), '... Rolename rejects anything which is not a RoleName');
350329 ok(!defined RoleName(bless {}, 'Foo'), '... Rolename rejects anything which is not a RoleName');
1010
1111 enum Letter => 'a'..'z', 'A'..'Z';
1212 enum Language => 'Perl 5', 'Perl 6', 'PASM', 'PIR'; # any others? ;)
13 enum Metacharacter => ['*', '+', '?', '.', '|', '(', ')', '[', ']', '\\'];
13 enum Metacharacter => '*', '+', '?', '.', '|', '(', ')', '[', ']', '\\';
1414
1515 my @valid_letters = ('a'..'z', 'A'..'Z');
1616
11 use strict;
22 use warnings;
33
4 use Test::More tests => 5;
4 use Test::More tests => 4;
55 use Test::Exception;
66
77 {
3838 use Moose::Util::TypeConstraints;
3939
4040 duck_type 'DuckType' => qw(quack);
41 duck_type 'SwanType' => [qw(honk)];
4241
4342 has duck => (
4443 isa => 'DuckType',
5049
5150 has swan => (
5251 isa => duck_type( [qw(honk)] ),
53 is => 'ro',
54 );
55
56 has other_swan => (
57 isa => 'SwanType',
5852 is => 'ro',
5953 );
6054
7569 lives_ok { DucktypeTest->new( duck => RubberDuck->new ) }
7670 'the RubberDuck lives okay';
7771
78 # try with the other constraint form
79 lives_ok { DucktypeTest->new( other_swan => Swan->new ) } 'but a Swan can honk';
00 use strict;
11 use warnings;
22
3 use Test::More tests => 3;
3 use Test::More tests => 2;
44
55 {
66 package Thingy;
1313 required => 1,
1414 handles => { 'invoke_callback' => 'execute' },
1515 );
16
17 has multiplier => (
18 traits => ['Code'],
19 is => 'ro',
20 isa => 'CodeRef',
21 required => 1,
22 handles => { 'multiply' => 'execute' },
23 );
2416 }
2517
2618 my $i = 0;
27 my $thingy = Thingy->new(
28 callback => sub { ++$i },
29 multiplier => sub { $_[0] * 2 }
30 );
19 my $thingy = Thingy->new(callback => sub { ++$i });
3120
3221 is($i, 0);
3322 $thingy->invoke_callback;
3423 is($i, 1);
35 is($thingy->multiply(3), 6);
117117 ## computerese
118118 API
119119 APIs
120 arrayrefs
121120 arity
122121 Baz
123122 Changelog
206205 featureful
207206 hackery
208207 hacktern
209 undeprecate
210208 wrappee
211209
212210 ## compound