revert half-upgraded package
Jonathan Yu
14 years ago
0 | 0 | Also see Moose::Manual::Delta for more details of, and workarounds |
1 | 1 | 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) | |
37 | 2 | |
38 | 3 | 0.92 Tue, Sep 22, 2009 |
39 | 4 | * Moose::Util::TypeConstraints |
86 | 51 | - Added more hooks to customize how roles are applied. The role |
87 | 52 | summation class, used to create composite roles, can now be changed |
88 | 53 | 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) | |
92 | 54 | |
93 | 55 | * Moose::Meta::Method::Delegation |
94 | 56 | - fixed delegated methods to make sure that any modifiers attached to |
161 | 161 | t/010_basics/019-destruction.t |
162 | 162 | t/010_basics/020-global-destruction-helper.pl |
163 | 163 | t/010_basics/020-global-destruction.t |
164 | t/010_basics/021-instance-new.t | |
164 | 165 | t/020_attributes/001_attribute_reader_generation.t |
165 | 166 | t/020_attributes/002_attribute_writer_generation.t |
166 | 167 | t/020_attributes/003_attribute_accessor_generation.t |
192 | 193 | t/020_attributes/029_accessor_context.t |
193 | 194 | t/020_attributes/030_non_alpha_attr_names.t |
194 | 195 | t/020_attributes/031_delegation_and_modifiers.t |
195 | t/020_attributes/032_delegation_arg_aliasing.t | |
196 | 196 | t/030_roles/001_meta_role.t |
197 | 197 | t/030_roles/002_role.t |
198 | 198 | t/030_roles/003_apply_role.t |
21 | 21 | ^\._.*$ |
22 | 22 | ^t\/600_todo_tests\/$ |
23 | 23 | \.shipit |
24 | ^grant-description | |
24 | 25 | ^Moose-.* |
25 | 26 | \.git.* |
32 | 32 | perl: 5.8.1 |
33 | 33 | resources: |
34 | 34 | license: http://dev.perl.org/licenses/ |
35 | version: 0.93 | |
35 | version: 0.92 |
40 | 40 | 'MooseX::AttributeHelpers' => '0.21', |
41 | 41 | 'MooseX::ClassAttribute' => '0.09', |
42 | 42 | 'MooseX::MethodAttributes' => '0.15', |
43 | 'MooseX::NonMoose' => '0.05', | |
44 | 43 | 'MooseX::Params::Validate' => '0.05', |
45 | 44 | 'MooseX::Singleton' => '0.19', |
46 | 45 | 'MooseX::StrictConstructor' => '0.07', |
0 | Moose version 0.93 | |
0 | Moose version 0.92 | |
1 | 1 | =========================== |
2 | 2 | |
3 | 3 | See the individual module documentation for more information |
37 | 37 | sub dump { |
38 | 38 | my $self = shift; |
39 | 39 | |
40 | my $meta = $self->meta; | |
41 | ||
42 | 40 | my $dump = ''; |
43 | 41 | |
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}; | |
46 | 45 | |
47 | 46 | if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') |
48 | 47 | && $attribute->has_label ) { |
49 | 48 | $dump .= $attribute->label; |
50 | 49 | } |
51 | 50 | else { |
52 | $dump .= $attribute->name; | |
51 | $dump .= $name; | |
53 | 52 | } |
54 | 53 | |
55 | 54 | my $reader = $attribute->get_read_method; |
87 | 86 | Internally, the metaclass for C<Point> has two |
88 | 87 | L<Moose::Meta::Attribute>. There are several methods for getting |
89 | 88 | 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: | |
96 | 103 | |
97 | 104 | print $point->meta->get_attribute('x')->type_constraint; |
98 | 105 | => Int |
192 | 199 | sub dump { |
193 | 200 | my $self = shift; |
194 | 201 | |
195 | my $meta = $self->meta; | |
196 | ||
197 | 202 | my $dump = ''; |
198 | 203 | |
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}; | |
201 | 207 | |
202 | 208 | if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') |
203 | 209 | && $attribute->has_label ) { |
214 | 220 | label, we use it, otherwise we use the attribute name: |
215 | 221 | |
216 | 222 | else { |
217 | $dump .= $attribute->name; | |
223 | $dump .= $name; | |
218 | 224 | } |
219 | 225 | |
220 | 226 | my $reader = $attribute->get_read_method; |
36 | 36 | sub dump { |
37 | 37 | my $self = shift; |
38 | 38 | |
39 | my $meta = $self->meta; | |
40 | ||
41 | 39 | my $dump = ''; |
42 | 40 | |
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}; | |
45 | 44 | |
46 | 45 | if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled') |
47 | 46 | && $attribute->has_label ) { |
48 | 47 | $dump .= $attribute->label; |
49 | 48 | } |
50 | 49 | else { |
51 | $dump .= $attribute->name; | |
50 | $dump .= $name; | |
52 | 51 | } |
53 | 52 | |
54 | 53 | my $reader = $attribute->get_read_method; |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 | |
300 | 300 | my $exporting_package = shift; |
301 | 301 | my $exporter = shift; |
302 | 302 | my $exports_from = shift; |
303 | my $export_to_main = shift; | |
303 | 304 | |
304 | 305 | return sub { |
305 | 306 | |
335 | 336 | |
336 | 337 | strict->import; |
337 | 338 | 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 | } | |
338 | 346 | |
339 | 347 | my $did_init_meta; |
340 | 348 | for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) { |
12 | 12 | Of course, as with any list of "best practices", these are really just |
13 | 13 | opinions. Feel free to ignore us. |
14 | 14 | |
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. | |
19 | 19 | |
20 | 20 | package Person; |
21 | 21 | |
22 | 22 | use Moose; |
23 | use namespace::autoclean; | |
24 | 23 | |
25 | 24 | # extends, roles, attributes, etc. |
26 | 25 | |
27 | 26 | # methods |
28 | 27 | |
28 | no Moose; | |
29 | ||
29 | 30 | __PACKAGE__->meta->make_immutable; |
30 | 31 | |
31 | 32 | 1; |
32 | 33 | |
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 | |
36 | 36 | built, these keywords are not needed needed. The C<make_immutable> |
37 | 37 | call allows Moose to speed up a lot of things, most notably object |
38 | 38 | construction. The trade-off is that you can no longer change the class |
39 | 39 | definition. |
40 | 40 | |
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>. | |
43 | 44 | |
44 | 45 | =head2 Never override C<new> |
45 | 46 |
10 | 10 | the L</STANDARD WORKFLOW> is very simple. The general gist is: clone the Git |
11 | 11 | repository, create a new topic branch, hack away, then find a committer to |
12 | 12 | review your changes. |
13 | ||
14 | Note that this document applies to both Moose and L<Class::MOP> development. | |
15 | 13 | |
16 | 14 | =head1 NEW FEATURES |
17 | 15 | |
227 | 225 | |
228 | 226 | Development releases are made without merging into the stable branch. |
229 | 227 | |
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 | ||
262 | 228 | =head1 EMERGENCY BUG WORKFLOW (for immediate release) |
263 | 229 | |
264 | 230 | Anyone can create the necessary fix by branching off of the stable branch: |
42 | 42 | |
43 | 43 | With this definition, we can call C<< $website->host >> and it "just |
44 | 44 | 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. | |
47 | 46 | |
48 | 47 | We can also define a mapping as a hash reference. This allows you to |
49 | 48 | rename methods as part of the mapping: |
14 | 14 | feature. If you encounter a problem and have a solution but don't see |
15 | 15 | it documented here, or think we missed an important feature, please |
16 | 16 | 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 | |
27 | 17 | |
28 | 18 | =head1 0.90 |
29 | 19 | |
72 | 62 | this may cause issues should be helpful. Metaclasses (classes that inherit |
73 | 63 | from L<Class::MOP::Object>) are currently exempt from this check, since at the |
74 | 64 | 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. | |
88 | 65 | |
89 | 66 | =back |
90 | 67 |
38 | 38 | Undef |
39 | 39 | Defined |
40 | 40 | Value |
41 | Num | |
42 | Int | |
41 | 43 | Str |
42 | Num | |
43 | Int | |
44 | 44 | ClassName |
45 | 45 | RoleName |
46 | 46 | Ref |
3 | 3 | use List::Util; |
4 | 4 | use List::MoreUtils; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 | |
25 | 25 | my ( $attr, $reader, $writer ) = @_; |
26 | 26 | return sub { |
27 | 27 | my ( $instance, $predicate ) = @_; |
28 | List::Util::first { $predicate->() } @{ $reader->($instance) }; | |
28 | &List::Util::first($predicate, @{ $reader->($instance) }); | |
29 | 29 | }; |
30 | 30 | } |
31 | 31 |
1 | 1 | package Moose::Meta::Attribute::Native::MethodProvider::Bool; |
2 | 2 | use Moose::Role; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
0 | 0 | package Moose::Meta::Attribute::Native::MethodProvider::Code; |
1 | 1 | use Moose::Role; |
2 | 2 | |
3 | our $VERSION = '0.93'; | |
3 | our $VERSION = '0.92'; | |
4 | 4 | $VERSION = eval $VERSION; |
5 | 5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | 6 | |
7 | 7 | sub execute : method { |
8 | 8 | my ( $attr, $reader, $writer ) = @_; |
9 | return sub { my ($self, @args) = @_; $reader->($self)->(@args) }; | |
9 | return sub { $reader->(@_)->(@_) }; | |
10 | 10 | } |
11 | 11 | |
12 | 12 | no Moose::Role; |
1 | 1 | package Moose::Meta::Attribute::Native::MethodProvider::Counter; |
2 | 2 | use Moose::Role; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
0 | 0 | package Moose::Meta::Attribute::Native::MethodProvider::Hash; |
1 | 1 | use Moose::Role; |
2 | 2 | |
3 | our $VERSION = '0.93'; | |
3 | our $VERSION = '0.92'; | |
4 | 4 | $VERSION = eval $VERSION; |
5 | 5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | 6 |
0 | 0 | package Moose::Meta::Attribute::Native::MethodProvider::String; |
1 | 1 | use Moose::Role; |
2 | 2 | |
3 | our $VERSION = '0.93'; | |
3 | our $VERSION = '0.92'; | |
4 | 4 | $VERSION = eval $VERSION; |
5 | 5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | 6 |
1 | 1 | package Moose::Meta::Attribute::Native::Trait::Array; |
2 | 2 | use Moose::Role; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
1 | 1 | use Moose::Role; |
2 | 2 | use Moose::Meta::Attribute::Native::MethodProvider::Bool; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
1 | 1 | use Moose::Role; |
2 | 2 | use Moose::Meta::Attribute::Native::MethodProvider::Code; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
1 | 1 | package Moose::Meta::Attribute::Native::Trait::Counter; |
2 | 2 | use Moose::Role; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
1 | 1 | package Moose::Meta::Attribute::Native::Trait::Hash; |
2 | 2 | use Moose::Role; |
3 | 3 | |
4 | our $VERSION = '0.93'; | |
4 | our $VERSION = '0.92'; | |
5 | 5 | $VERSION = eval $VERSION; |
6 | 6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | 7 |
0 | 0 | package Moose::Meta::Attribute::Native::Trait::Number; |
1 | 1 | use Moose::Role; |
2 | 2 | |
3 | our $VERSION = '0.93'; | |
3 | our $VERSION = '0.92'; | |
4 | 4 | $VERSION = eval $VERSION; |
5 | 5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | 6 |
0 | 0 | package Moose::Meta::Attribute::Native::Trait::String; |
1 | 1 | use Moose::Role; |
2 | 2 | |
3 | our $VERSION = '0.93'; | |
3 | our $VERSION = '0.92'; | |
4 | 4 | $VERSION = eval $VERSION; |
5 | 5 | our $AUTHORITY = 'cpan:STEVAN'; |
6 | 6 |
2 | 2 | use Moose::Role; |
3 | 3 | use Moose::Util::TypeConstraints; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 | |
145 | 145 | exception. If you find a bug please either email me, or add the bug |
146 | 146 | to cpan-RT. |
147 | 147 | |
148 | =head1 SEE ALSO | |
149 | ||
150 | Documentation for Moose native traits starts at L<Moose::Meta::Attribute Native> | |
151 | ||
152 | 148 | =head1 AUTHORS |
153 | 149 | |
154 | 150 | Yuval Kogman |
0 | 0 | package Moose::Meta::Attribute::Native; |
1 | 1 | |
2 | our $VERSION = '0.93'; | |
2 | our $VERSION = '0.92'; | |
3 | 3 | $VERSION = eval $VERSION; |
4 | 4 | our $AUTHORITY = 'cpan:STEVAN'; |
5 | 5 |
4 | 4 | use warnings; |
5 | 5 | |
6 | 6 | use Scalar::Util 'blessed', 'weaken'; |
7 | use List::MoreUtils 'any'; | |
8 | use Try::Tiny; | |
9 | 7 | use overload (); |
10 | 8 | |
11 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
12 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 11 | |
14 | 12 | use Moose::Meta::Method::Accessor; |
59 | 57 | # for metatrait aliases. |
60 | 58 | sub does { |
61 | 59 | my ($self, $role_name) = @_; |
62 | my $name = try { | |
60 | my $name = eval { | |
63 | 61 | Moose::Util::resolve_metatrait_alias(Attribute => $role_name) |
64 | 62 | }; |
65 | 63 | return 0 if !defined($name); # failed to load class |
319 | 317 | |
320 | 318 | if (exists $options->{isa}) { |
321 | 319 | if (exists $options->{does}) { |
322 | if (try { $options->{isa}->can('does') }) { | |
320 | if (eval { $options->{isa}->can('does') }) { | |
323 | 321 | ($options->{isa}->does($options->{does})) |
324 | 322 | || $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); |
325 | 323 | } |
657 | 655 | my %handles = $self->_canonicalize_handles; |
658 | 656 | my $associated_class = $self->associated_class; |
659 | 657 | foreach my $handle (keys %handles) { |
660 | next unless any { $handle eq $_ } | |
661 | map { $_->name } | |
662 | @{ $self->associated_methods }; | |
663 | 658 | $self->associated_class->remove_method($handle); |
664 | 659 | } |
665 | 660 | } |
744 | 739 | sub _make_delegation_method { |
745 | 740 | my ( $self, $handle_name, $method_to_call ) = @_; |
746 | 741 | |
742 | my $method_body; | |
743 | ||
744 | $method_body = $method_to_call | |
745 | if 'CODE' eq ref($method_to_call); | |
746 | ||
747 | 747 | my @curried_arguments; |
748 | 748 | |
749 | 749 | ($method_to_call, @curried_arguments) = @$method_to_call |
4 | 4 | |
5 | 5 | use Class::MOP; |
6 | 6 | |
7 | our $VERSION = '0.93'; | |
7 | our $VERSION = '0.92'; | |
8 | 8 | $VERSION = eval $VERSION; |
9 | 9 | our $AUTHORITY = 'cpan:STEVAN'; |
10 | 10 |
10 | 10 | use List::MoreUtils qw( any all uniq first_index ); |
11 | 11 | use Scalar::Util 'weaken', 'blessed'; |
12 | 12 | |
13 | our $VERSION = '0.93'; | |
13 | our $VERSION = '0.92'; | |
14 | 14 | $VERSION = eval $VERSION; |
15 | 15 | our $AUTHORITY = 'cpan:STEVAN'; |
16 | 16 |
3 | 3 | use strict; |
4 | 4 | use warnings; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
3 | 3 | use strict; |
4 | 4 | use warnings; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
5 | 5 | |
6 | 6 | use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr'; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | our $AUTHORITY = 'cpan:STEVAN'; |
10 | 10 | |
11 | 11 | use base 'Moose::Meta::Method', |
55 | 55 | # the author, after all, nothing is free) |
56 | 56 | my $source = 'sub {'; |
57 | 57 | $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);}; | |
58 | 61 | |
59 | 62 | $source .= "\n" . 'my $class = Scalar::Util::blessed($_instance) || $_instance;'; |
60 | 63 |
6 | 6 | use Carp 'confess'; |
7 | 7 | use Scalar::Util 'blessed', 'weaken'; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 | |
103 | 103 | object => $instance |
104 | 104 | ); |
105 | 105 | } |
106 | unshift @_, @{ $self->curried_arguments }; | |
107 | $proxy->$method_to_call(@_); | |
106 | my @args = (@{ $self->curried_arguments }, @_); | |
107 | $proxy->$method_to_call(@args); | |
108 | 108 | }; |
109 | 109 | } |
110 | 110 |
7 | 7 | use Scalar::Util 'blessed', 'weaken'; |
8 | 8 | use Try::Tiny (); |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | our $VERSION = '0.93'; | |
5 | our $VERSION = '0.92'; | |
6 | 6 | $VERSION = eval $VERSION; |
7 | 7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | 8 |
7 | 7 | |
8 | 8 | use Moose::Meta::Role::Composite; |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
6 | 6 | use Moose::Util 'english_list'; |
7 | 7 | use Scalar::Util 'weaken', 'blessed'; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
5 | 5 | |
6 | 6 | use Scalar::Util 'blessed'; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 |
5 | 5 | |
6 | 6 | use Scalar::Util 'blessed'; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 |
3 | 3 | use warnings; |
4 | 4 | use metaclass; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
5 | 5 | |
6 | 6 | use Scalar::Util 'blessed'; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 |
7 | 7 | |
8 | 8 | use base qw(Moose::Meta::Role::Method::Required); |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
9 | 9 | |
10 | 10 | use base qw(Class::MOP::Object); |
11 | 11 | |
12 | our $VERSION = '0.93'; | |
12 | our $VERSION = '0.92'; | |
13 | 13 | $VERSION = eval $VERSION; |
14 | 14 | our $AUTHORITY = 'cpan:STEVAN'; |
15 | 15 |
3 | 3 | use strict; |
4 | 4 | use warnings; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
6 | 6 | |
7 | 7 | use Scalar::Util 'blessed'; |
8 | 8 | use Carp 'confess'; |
9 | use Sub::Name 'subname'; | |
9 | 10 | use Devel::GlobalDestruction 'in_global_destruction'; |
10 | 11 | |
11 | our $VERSION = '0.93'; | |
12 | our $VERSION = '0.92'; | |
12 | 13 | $VERSION = eval $VERSION; |
13 | 14 | our $AUTHORITY = 'cpan:STEVAN'; |
14 | 15 | |
70 | 71 | } |
71 | 72 | }, |
72 | 73 | { |
73 | name => '_attribute_map', | |
74 | attr_reader => '_attribute_map', | |
74 | name => 'attribute_map', | |
75 | attr_reader => 'get_attribute_map', | |
75 | 76 | methods => { |
76 | 77 | get => 'get_attribute', |
77 | 78 | get_keys => 'get_attribute_list', |
180 | 181 | else { |
181 | 182 | $attr_desc = { @_ }; |
182 | 183 | } |
183 | $self->_attribute_map->{$name} = $attr_desc; | |
184 | $self->get_attribute_map->{$name} = $attr_desc; | |
184 | 185 | } |
185 | 186 | |
186 | 187 | sub add_required_methods { |
565 | 566 | # |
566 | 567 | # has 'attribute_map' => ( |
567 | 568 | # metaclass => 'Hash', |
568 | # reader => '_attribute_map', | |
569 | # reader => 'get_attribute_map', | |
569 | 570 | # isa => 'HashRef[Str]', |
570 | 571 | # provides => { |
571 | 572 | # # 'set' => 'add_attribute' # has some special crap in it |
817 | 818 | |
818 | 819 | =item B<< $metarole->has_attribute($attribute_name) >> |
819 | 820 | |
821 | =item B<< $metarole->get_attribute_map >> | |
822 | ||
820 | 823 | =item B<< $metarole->get_attribute_list >> |
821 | 824 | |
822 | 825 | =item B<< $metarole->add_attribute($name, %options) >> |
6 | 6 | |
7 | 7 | use Scalar::Util 'blessed'; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
7 | 7 | use Moose::Meta::Attribute; |
8 | 8 | use Moose::Util::TypeConstraints (); |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
6 | 6 | use Scalar::Util 'blessed'; |
7 | 7 | use Moose::Util::TypeConstraints (); |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
9 | 9 | |
10 | 10 | use Moose::Util::TypeConstraints (); |
11 | 11 | |
12 | our $VERSION = '0.93'; | |
12 | our $VERSION = '0.92'; | |
13 | 13 | $VERSION = eval $VERSION; |
14 | 14 | our $AUTHORITY = 'cpan:STEVAN'; |
15 | 15 |
5 | 5 | |
6 | 6 | use Moose::Util::TypeConstraints (); |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 |
3 | 3 | use warnings; |
4 | 4 | use metaclass; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
7 | 7 | use Moose::Util::TypeConstraints; |
8 | 8 | use Moose::Meta::TypeConstraint::Parameterizable; |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
6 | 6 | |
7 | 7 | use Scalar::Util 'blessed'; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
6 | 6 | use Scalar::Util 'blessed'; |
7 | 7 | use Moose::Util::TypeConstraints (); |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
6 | 6 | |
7 | 7 | use Moose::Meta::TypeCoercion::Union; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
12 | 12 | |
13 | 13 | use base qw(Class::MOP::Object); |
14 | 14 | |
15 | our $VERSION = '0.93'; | |
15 | our $VERSION = '0.92'; | |
16 | 16 | $VERSION = eval $VERSION; |
17 | 17 | our $AUTHORITY = 'cpan:STEVAN'; |
18 | 18 |
11 | 11 | use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class'; |
12 | 12 | use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class'; |
13 | 13 | |
14 | our $VERSION = '0.93'; | |
14 | our $VERSION = '0.92'; | |
15 | 15 | $VERSION = eval $VERSION; |
16 | 16 | our $AUTHORITY = 'cpan:STEVAN'; |
17 | 17 | |
18 | 18 | sub new { |
19 | 19 | 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); | |
20 | 23 | |
21 | 24 | my $params = $class->BUILDARGS(@_); |
22 | 25 | |
117 | 120 | my ($self, $role_name) = @_; |
118 | 121 | my $meta = Class::MOP::class_of($self); |
119 | 122 | (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()"); | |
121 | 124 | foreach my $class ($meta->class_precedence_list) { |
122 | 125 | my $m = $meta->initialize($class); |
123 | 126 | return 1 |
6 | 6 | |
7 | 7 | use Sub::Exporter; |
8 | 8 | |
9 | our $VERSION = '0.93'; | |
9 | our $VERSION = '0.92'; | |
10 | 10 | $VERSION = eval $VERSION; |
11 | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | 12 |
3 | 3 | use warnings; |
4 | 4 | use Scalar::Util 'blessed'; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
5 | 5 | use Class::MOP; |
6 | 6 | use Scalar::Util 'blessed', 'looks_like_number'; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 | |
13 | 13 | |
14 | 14 | sub Ref { ref($_[0]) } |
15 | 15 | |
16 | sub Str { defined($_[0]) && ref(\$_[0]) eq 'SCALAR' } | |
16 | sub Str { defined($_[0]) && !ref($_[0]) } | |
17 | 17 | |
18 | 18 | sub Num { !ref($_[0]) && looks_like_number($_[0]) } |
19 | 19 |
5 | 5 | use Scalar::Util qw( blessed reftype ); |
6 | 6 | use Moose::Exporter; |
7 | 7 | |
8 | our $VERSION = '0.93'; | |
8 | our $VERSION = '0.92'; | |
9 | 9 | $VERSION = eval $VERSION; |
10 | 10 | our $AUTHORITY = 'cpan:STEVAN'; |
11 | 11 | |
364 | 364 | if ( ref $type_name eq 'ARRAY' && !@methods ) { |
365 | 365 | @methods = @$type_name; |
366 | 366 | $type_name = undef; |
367 | } | |
368 | if ( @methods == 1 && ref $methods[0] eq 'ARRAY' ) { | |
369 | @methods = @{ $methods[0] }; | |
370 | 367 | } |
371 | 368 | |
372 | 369 | register_type_constraint( |
414 | 411 | @values = @$type_name; |
415 | 412 | $type_name = undef; |
416 | 413 | } |
417 | if ( @values == 1 && ref $values[0] eq 'ARRAY' ) { | |
418 | @values = @{ $values[0] }; | |
419 | } | |
420 | 414 | ( scalar @values >= 2 ) |
421 | 415 | || __PACKAGE__->_throw_error( |
422 | 416 | "You must have at least two values to enumerate through"); |
661 | 655 | subtype 'Ref' => as 'Defined' => where { ref($_) } => |
662 | 656 | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Ref; |
663 | 657 | |
664 | subtype 'Str' => as 'Value' => where { ref(\$_) eq 'SCALAR' } => | |
658 | subtype 'Str' => as 'Value' => where {1} => | |
665 | 659 | optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Str; |
666 | 660 | |
667 | 661 | subtype 'Num' => as 'Str' => |
887 | 881 | Undef |
888 | 882 | Defined |
889 | 883 | Value |
884 | Num | |
885 | Int | |
890 | 886 | Str |
891 | Num | |
892 | Int | |
893 | 887 | ClassName |
894 | 888 | RoleName |
895 | 889 | Ref |
1031 | 1025 | Creates a type constraint for either C<undef> or something of the |
1032 | 1026 | given type. |
1033 | 1027 | |
1034 | =item B<duck_type ($name, \@methods)> | |
1028 | =item B<duck_type ($name, @methods)> | |
1035 | 1029 | |
1036 | 1030 | 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>. | |
1038 | 1032 | |
1039 | 1033 | This is intended as an easy way to accept non-Moose objects that |
1040 | 1034 | provide a certain interface. If you're using Moose classes, we |
1042 | 1036 | |
1043 | 1037 | =item B<duck_type (\@methods)> |
1044 | 1038 | |
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: | |
1048 | 1042 | |
1049 | 1043 | has 'cache' => ( |
1050 | 1044 | is => 'ro', |
1051 | 1045 | isa => duck_type( [qw( get_set )] ), |
1052 | 1046 | ); |
1053 | 1047 | |
1054 | =item B<enum ($name, \@values)> | |
1048 | =item B<enum ($name, @values)> | |
1055 | 1049 | |
1056 | 1050 | This will create a basic subtype for a given set of strings. |
1057 | 1051 | 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. | |
1059 | 1053 | See the L<SYNOPSIS> for a simple example. |
1060 | 1054 | |
1061 | 1055 | B<NOTE:> This is not a true proper enum type, it is simply |
1063 | 1057 | |
1064 | 1058 | =item B<enum (\@values)> |
1065 | 1059 | |
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: | |
1069 | 1063 | |
1070 | 1064 | has 'sort_order' => ( |
1071 | 1065 | is => 'ro', |
7 | 7 | use Scalar::Util 'blessed'; |
8 | 8 | use Class::MOP 0.60; |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
3 | 3 | |
4 | 4 | use 5.008; |
5 | 5 | |
6 | our $VERSION = '0.93'; | |
6 | our $VERSION = '0.92'; | |
7 | 7 | $VERSION = eval $VERSION; |
8 | 8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | 9 |
7 | 7 | |
8 | 8 | use Moose::Util 'does_role', 'find_meta'; |
9 | 9 | |
10 | our $VERSION = '0.93'; | |
10 | our $VERSION = '0.92'; | |
11 | 11 | $VERSION = eval $VERSION; |
12 | 12 | our $AUTHORITY = 'cpan:STEVAN'; |
13 | 13 |
4 | 4 | |
5 | 5 | use Class::MOP; |
6 | 6 | |
7 | our $VERSION = '0.93'; | |
7 | our $VERSION = '0.92'; | |
8 | 8 | $VERSION = eval $VERSION; |
9 | 9 | our $AUTHORITY = 'cpan:STEVAN'; |
10 | 10 |
40 | 40 | sub dump { |
41 | 41 | my $self = shift; |
42 | 42 | |
43 | my $meta = $self->meta; | |
44 | ||
45 | 43 | my $dump = ''; |
46 | 44 | |
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}; | |
49 | 48 | |
50 | 49 | if ( $attribute->isa('MyApp::Meta::Attribute::Labeled') |
51 | 50 | && $attribute->has_label ) { |
52 | 51 | $dump .= $attribute->label; |
53 | 52 | } |
54 | 53 | else { |
55 | $dump .= $attribute->name; | |
54 | $dump .= $name; | |
56 | 55 | } |
57 | 56 | |
58 | 57 | my $reader = $attribute->get_read_method; |
39 | 39 | sub dump { |
40 | 40 | my $self = shift; |
41 | 41 | |
42 | my $meta = $self->meta; | |
43 | ||
44 | 42 | my $dump = ''; |
45 | 43 | |
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}; | |
48 | 47 | |
49 | 48 | if ( $attribute->does('MyApp::Meta::Attribute::Trait::Labeled') |
50 | 49 | && $attribute->has_label ) { |
51 | 50 | $dump .= $attribute->label; |
52 | 51 | } |
53 | 52 | else { |
54 | $dump .= $attribute->name; | |
53 | $dump .= $name; | |
55 | 54 | } |
56 | 55 | |
57 | 56 | my $reader = $attribute->get_read_method; |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | use Test::More tests => 29; | |
5 | use Test::More tests => 30; | |
6 | 6 | use Test::Exception; |
7 | 7 | |
8 | 8 | |
21 | 21 | |
22 | 22 | dies_ok { |
23 | 23 | Foo->meta->has_method() |
24 | } '... has_method requires an arg'; | |
25 | ||
26 | dies_ok { | |
27 | Foo->meta->has_method('') | |
24 | 28 | } '... has_method requires an arg'; |
25 | 29 | |
26 | 30 | can_ok('Foo', 'does'); |
4 | 4 | |
5 | 5 | use lib 't/lib', 'lib'; |
6 | 6 | |
7 | use Test::More tests => 4; | |
8 | use Test::Exception; | |
7 | use Test::More tests => 5; | |
9 | 8 | |
10 | 9 | |
11 | 10 | |
12 | 11 | { |
13 | ||
14 | 12 | package Bar; |
15 | 13 | use Moose; |
16 | 14 | |
17 | ::lives_ok { extends 'Foo' } 'loaded Foo superclass correctly'; | |
15 | eval { extends 'Foo'; }; | |
16 | ::ok(!$@, '... loaded Foo superclass correctly'); | |
18 | 17 | } |
19 | 18 | |
20 | 19 | { |
21 | ||
22 | 20 | package Baz; |
23 | 21 | use Moose; |
24 | 22 | |
25 | ::lives_ok { extends 'Bar' } 'loaded (inline) Bar superclass correctly'; | |
23 | eval { extends 'Bar'; }; | |
24 | ::ok(!$@, '... loaded (inline) Bar superclass correctly'); | |
26 | 25 | } |
27 | 26 | |
28 | 27 | { |
29 | ||
30 | 28 | package Foo::Bar; |
31 | 29 | use Moose; |
32 | 30 | |
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'); | |
35 | 33 | } |
36 | 34 | |
37 | 35 | { |
38 | ||
39 | 36 | package Bling; |
40 | 37 | use Moose; |
41 | 38 | |
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'); | |
45 | 42 | } |
46 | 43 |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
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 | } | |
7 | 11 | |
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' ); | |
11 | 15 | |
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' ); |
17 | 17 | throws_ok { Foo->new(undef) } qr/^\QSingle parameters to new() must be a HASH ref/, |
18 | 18 | 'A single non-hashref arg to a constructor throws an error'; |
19 | 19 | |
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()/, | |
21 | 21 | '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 | } |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | use Test::More tests => 48; | |
5 | use Test::More tests => 39; | |
6 | 6 | use Test::Exception; |
7 | 7 | |
8 | 8 | =pod |
75 | 75 | |
76 | 76 | sub child_g_method_1 { "g1" } |
77 | 77 | |
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 | ||
90 | 78 | package Parent; |
91 | 79 | use Moose; |
92 | ||
93 | sub parent_method_1 { "parent_1" } | |
94 | ::can_ok('Parent', 'parent_method_1'); | |
95 | 80 | |
96 | 81 | ::dies_ok { |
97 | 82 | has child_a => ( |
180 | 165 | handles => ["child_g_method_1"], |
181 | 166 | ); |
182 | 167 | } "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 | ||
207 | 168 | |
208 | 169 | sub parent_method { "p" } |
209 | 170 | } |
217 | 178 | isa_ok( $p->child_d, "ChildD" ); |
218 | 179 | isa_ok( $p->child_e, "ChildE" ); |
219 | 180 | isa_ok( $p->child_f, "ChildF" ); |
220 | isa_ok( $p->child_i, "ChildI" ); | |
221 | 181 | |
222 | 182 | ok(!$p->can('child_g'), '... no child_g accessor defined'); |
223 | ok(!$p->can('child_h'), '... no child_h accessor defined'); | |
224 | 183 | |
225 | 184 | |
226 | 185 | is( $p->parent_method, "p", "parent method" ); |
255 | 214 | |
256 | 215 | can_ok( $p, "child_g_method_1" ); |
257 | 216 | 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 | #!/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"); |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
5 | use Test::More tests => 297; | |
5 | use Test::More tests => 277; | |
6 | 6 | use Test::Exception; |
7 | 7 | |
8 | 8 | use Scalar::Util (); |
14 | 14 | my $SCALAR_REF = \(my $var); |
15 | 15 | |
16 | 16 | no warnings 'once'; # << I *hates* that warning ... |
17 | my $GLOB = *GLOB_REF; | |
18 | my $GLOB_REF = \$GLOB; | |
17 | my $GLOB_REF = \*GLOB_REF; | |
19 | 18 | |
20 | 19 | my $fh; |
21 | 20 | open($fh, '<', $0) || die "Could not open $0 for the test"; |
32 | 31 | ok(defined Any({}), '... Any accepts anything'); |
33 | 32 | ok(defined Any(sub {}), '... Any accepts anything'); |
34 | 33 | ok(defined Any($SCALAR_REF), '... Any accepts anything'); |
35 | ok(defined Any($GLOB), '... Any accepts anything'); | |
36 | 34 | ok(defined Any($GLOB_REF), '... Any accepts anything'); |
37 | 35 | ok(defined Any($fh), '... Any accepts anything'); |
38 | 36 | ok(defined Any(qr/../), '... Any accepts anything'); |
47 | 45 | ok(defined Item({}), '... Item is the base type, so accepts anything'); |
48 | 46 | ok(defined Item(sub {}), '... Item is the base type, so accepts anything'); |
49 | 47 | 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'); | |
51 | 48 | ok(defined Item($GLOB_REF), '... Item is the base type, so accepts anything'); |
52 | 49 | ok(defined Item($fh), '... Item is the base type, so accepts anything'); |
53 | 50 | ok(defined Item(qr/../), '... Item is the base type, so accepts anything'); |
62 | 59 | ok(defined Defined({}), '... Defined accepts anything which is defined'); |
63 | 60 | ok(defined Defined(sub {}), '... Defined accepts anything which is defined'); |
64 | 61 | ok(defined Defined($SCALAR_REF), '... Defined accepts anything which is defined'); |
65 | ok(defined Defined($GLOB), '... Defined accepts anything which is defined'); | |
66 | 62 | ok(defined Defined($GLOB_REF), '... Defined accepts anything which is defined'); |
67 | 63 | ok(defined Defined($fh), '... Defined accepts anything which is defined'); |
68 | 64 | ok(defined Defined(qr/../), '... Defined accepts anything which is defined'); |
77 | 73 | ok(!defined Undef({}), '... Undef accepts anything which is not defined'); |
78 | 74 | ok(!defined Undef(sub {}), '... Undef accepts anything which is not defined'); |
79 | 75 | ok(!defined Undef($SCALAR_REF), '... Undef accepts anything which is not defined'); |
80 | ok(!defined Undef($GLOB), '... Undef accepts anything which is not defined'); | |
81 | 76 | ok(!defined Undef($GLOB_REF), '... Undef accepts anything which is not defined'); |
82 | 77 | ok(!defined Undef($fh), '... Undef accepts anything which is not defined'); |
83 | 78 | ok(!defined Undef(qr/../), '... Undef accepts anything which is not defined'); |
93 | 88 | ok(!defined Bool({}), '... Bool rejects anything which is not a 1 or 0 or "" or undef'); |
94 | 89 | ok(!defined Bool(sub {}), '... Bool rejects anything which is not a 1 or 0 or "" or undef'); |
95 | 90 | 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'); | |
97 | 91 | ok(!defined Bool($GLOB_REF), '... Bool rejects anything which is not a 1 or 0 or "" or undef'); |
98 | 92 | ok(!defined Bool($fh), '... Bool rejects anything which is not a 1 or 0 or "" or undef'); |
99 | 93 | ok(!defined Bool(qr/../), '... Bool rejects anything which is not a 1 or 0 or "" or undef'); |
108 | 102 | ok(!defined Value({}), '... Value rejects anything which is not a Value'); |
109 | 103 | ok(!defined Value(sub {}), '... Value rejects anything which is not a Value'); |
110 | 104 | 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'); | |
112 | 105 | ok(!defined Value($GLOB_REF), '... Value rejects anything which is not a Value'); |
113 | 106 | ok(!defined Value($fh), '... Value rejects anything which is not a Value'); |
114 | 107 | ok(!defined Value(qr/../), '... Value rejects anything which is not a Value'); |
123 | 116 | ok(defined Ref({}), '... Ref rejects anything which is not a Ref'); |
124 | 117 | ok(defined Ref(sub {}), '... Ref rejects anything which is not a Ref'); |
125 | 118 | 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'); | |
127 | 119 | ok(defined Ref($GLOB_REF), '... Ref rejects anything which is not a Ref'); |
128 | 120 | ok(defined Ref($fh), '... Ref rejects anything which is not a Ref'); |
129 | 121 | ok(defined Ref(qr/../), '... Ref rejects anything which is not a Ref'); |
140 | 132 | ok(!defined Int({}), '... Int rejects anything which is not a Int'); |
141 | 133 | ok(!defined Int(sub {}), '... Int rejects anything which is not a Int'); |
142 | 134 | 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'); | |
144 | 135 | ok(!defined Int($GLOB_REF), '... Int rejects anything which is not a Int'); |
145 | 136 | ok(!defined Int($fh), '... Int rejects anything which is not a Int'); |
146 | 137 | ok(!defined Int(qr/../), '... Int rejects anything which is not a Int'); |
157 | 148 | ok(!defined Num({}), '... Num rejects anything which is not a Num'); |
158 | 149 | ok(!defined Num(sub {}), '... Num rejects anything which is not a Num'); |
159 | 150 | 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'); | |
161 | 151 | ok(!defined Num($GLOB_REF), '... Num rejects anything which is not a Num'); |
162 | 152 | ok(!defined Num($fh), '... Num rejects anything which is not a Num'); |
163 | 153 | ok(!defined Num(qr/../), '... Num rejects anything which is not a Num'); |
173 | 163 | ok(!defined Str(sub {}), '... Str rejects anything which is not a Str'); |
174 | 164 | ok(!defined Str($SCALAR_REF), '... Str rejects anything which is not a Str'); |
175 | 165 | 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'); | |
177 | 166 | ok(!defined Str($GLOB_REF), '... Str rejects anything which is not a Str'); |
178 | 167 | ok(!defined Str(qr/../), '... Str rejects anything which is not a Str'); |
179 | 168 | ok(!defined Str(bless {}, 'Foo'), '... Str rejects anything which is not a Str'); |
187 | 176 | ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef'); |
188 | 177 | ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef'); |
189 | 178 | 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'); | |
191 | 179 | ok(!defined ScalarRef($GLOB_REF), '... ScalarRef rejects anything which is not a ScalarRef'); |
192 | 180 | ok(!defined ScalarRef($fh), '... ScalarRef rejects anything which is not a ScalarRef'); |
193 | 181 | ok(!defined ScalarRef(qr/../), '... ScalarRef rejects anything which is not a ScalarRef'); |
202 | 190 | ok(!defined ArrayRef({}), '... ArrayRef rejects anything which is not a ArrayRef'); |
203 | 191 | ok(!defined ArrayRef(sub {}), '... ArrayRef rejects anything which is not a ArrayRef'); |
204 | 192 | 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'); | |
206 | 193 | ok(!defined ArrayRef($GLOB_REF), '... ArrayRef rejects anything which is not a ArrayRef'); |
207 | 194 | ok(!defined ArrayRef($fh), '... ArrayRef rejects anything which is not a ArrayRef'); |
208 | 195 | ok(!defined ArrayRef(qr/../), '... ArrayRef rejects anything which is not a ArrayRef'); |
217 | 204 | ok(defined HashRef({}), '... HashRef accepts anything which is a HashRef'); |
218 | 205 | ok(!defined HashRef(sub {}), '... HashRef rejects anything which is not a HashRef'); |
219 | 206 | 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'); | |
221 | 207 | ok(!defined HashRef($GLOB_REF), '... HashRef rejects anything which is not a HashRef'); |
222 | 208 | ok(!defined HashRef($fh), '... HashRef rejects anything which is not a HashRef'); |
223 | 209 | ok(!defined HashRef(qr/../), '... HashRef rejects anything which is not a HashRef'); |
232 | 218 | ok(!defined CodeRef({}), '... CodeRef rejects anything which is not a CodeRef'); |
233 | 219 | ok(defined CodeRef(sub {}), '... CodeRef accepts anything which is a CodeRef'); |
234 | 220 | 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'); | |
236 | 221 | ok(!defined CodeRef($GLOB_REF), '... CodeRef rejects anything which is not a CodeRef'); |
237 | 222 | ok(!defined CodeRef($fh), '... CodeRef rejects anything which is not a CodeRef'); |
238 | 223 | ok(!defined CodeRef(qr/../), '... CodeRef rejects anything which is not a CodeRef'); |
247 | 232 | ok(!defined RegexpRef({}), '... RegexpRef rejects anything which is not a RegexpRef'); |
248 | 233 | ok(!defined RegexpRef(sub {}), '... RegexpRef rejects anything which is not a RegexpRef'); |
249 | 234 | 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'); | |
251 | 235 | ok(!defined RegexpRef($GLOB_REF), '... RegexpRef rejects anything which is not a RegexpRef'); |
252 | 236 | ok(!defined RegexpRef($fh), '... RegexpRef rejects anything which is not a RegexpRef'); |
253 | 237 | ok(defined RegexpRef(qr/../), '... RegexpRef accepts anything which is a RegexpRef'); |
262 | 246 | ok(!defined GlobRef({}), '... GlobRef rejects anything which is not a GlobRef'); |
263 | 247 | ok(!defined GlobRef(sub {}), '... GlobRef rejects anything which is not a GlobRef'); |
264 | 248 | 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'); | |
266 | 249 | ok(defined GlobRef($GLOB_REF), '... GlobRef accepts anything which is a GlobRef'); |
267 | 250 | ok(defined GlobRef($fh), '... GlobRef accepts anything which is a GlobRef'); |
268 | 251 | ok(!defined GlobRef($fh_obj), '... GlobRef rejects anything which is not a GlobRef'); |
278 | 261 | ok(!defined FileHandle({}), '... FileHandle rejects anything which is not a FileHandle'); |
279 | 262 | ok(!defined FileHandle(sub {}), '... FileHandle rejects anything which is not a FileHandle'); |
280 | 263 | 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'); | |
282 | 264 | ok(!defined FileHandle($GLOB_REF), '... FileHandle rejects anything which is not a FileHandle'); |
283 | 265 | ok(defined FileHandle($fh), '... FileHandle accepts anything which is a FileHandle'); |
284 | 266 | ok(defined FileHandle($fh_obj), '... FileHandle accepts anything which is a FileHandle'); |
294 | 276 | ok(!defined Object({}), '... Object rejects anything which is not blessed'); |
295 | 277 | ok(!defined Object(sub {}), '... Object rejects anything which is not blessed'); |
296 | 278 | ok(!defined Object($SCALAR_REF), '... Object rejects anything which is not blessed'); |
297 | ok(!defined Object($GLOB), '... Object rejects anything which is not blessed'); | |
298 | 279 | ok(!defined Object($GLOB_REF), '... Object rejects anything which is not blessed'); |
299 | 280 | ok(!defined Object($fh), '... Object rejects anything which is not blessed'); |
300 | 281 | ok(!defined Object(qr/../), '... Object rejects anything which is not blessed'); |
318 | 299 | ok(!defined ClassName(sub {}), '... ClassName rejects anything which is not a ClassName'); |
319 | 300 | ok(!defined ClassName($SCALAR_REF), '... ClassName rejects anything which is not a ClassName'); |
320 | 301 | 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'); | |
322 | 302 | ok(!defined ClassName($GLOB_REF), '... ClassName rejects anything which is not a ClassName'); |
323 | 303 | ok(!defined ClassName(qr/../), '... ClassName rejects anything which is not a ClassName'); |
324 | 304 | ok(!defined ClassName(bless {}, 'Foo'), '... ClassName rejects anything which is not a ClassName'); |
344 | 324 | ok(!defined RoleName(sub {}), '... Rolename rejects anything which is not a RoleName'); |
345 | 325 | ok(!defined RoleName($SCALAR_REF), '... Rolename rejects anything which is not a RoleName'); |
346 | 326 | 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'); | |
348 | 327 | ok(!defined RoleName($GLOB_REF), '... Rolename rejects anything which is not a RoleName'); |
349 | 328 | ok(!defined RoleName(qr/../), '... Rolename rejects anything which is not a RoleName'); |
350 | 329 | ok(!defined RoleName(bless {}, 'Foo'), '... Rolename rejects anything which is not a RoleName'); |
10 | 10 | |
11 | 11 | enum Letter => 'a'..'z', 'A'..'Z'; |
12 | 12 | enum Language => 'Perl 5', 'Perl 6', 'PASM', 'PIR'; # any others? ;) |
13 | enum Metacharacter => ['*', '+', '?', '.', '|', '(', ')', '[', ']', '\\']; | |
13 | enum Metacharacter => '*', '+', '?', '.', '|', '(', ')', '[', ']', '\\'; | |
14 | 14 | |
15 | 15 | my @valid_letters = ('a'..'z', 'A'..'Z'); |
16 | 16 |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 | |
4 | use Test::More tests => 5; | |
4 | use Test::More tests => 4; | |
5 | 5 | use Test::Exception; |
6 | 6 | |
7 | 7 | { |
38 | 38 | use Moose::Util::TypeConstraints; |
39 | 39 | |
40 | 40 | duck_type 'DuckType' => qw(quack); |
41 | duck_type 'SwanType' => [qw(honk)]; | |
42 | 41 | |
43 | 42 | has duck => ( |
44 | 43 | isa => 'DuckType', |
50 | 49 | |
51 | 50 | has swan => ( |
52 | 51 | isa => duck_type( [qw(honk)] ), |
53 | is => 'ro', | |
54 | ); | |
55 | ||
56 | has other_swan => ( | |
57 | isa => 'SwanType', | |
58 | 52 | is => 'ro', |
59 | 53 | ); |
60 | 54 | |
75 | 69 | lives_ok { DucktypeTest->new( duck => RubberDuck->new ) } |
76 | 70 | 'the RubberDuck lives okay'; |
77 | 71 | |
78 | # try with the other constraint form | |
79 | lives_ok { DucktypeTest->new( other_swan => Swan->new ) } 'but a Swan can honk'; |
0 | 0 | use strict; |
1 | 1 | use warnings; |
2 | 2 | |
3 | use Test::More tests => 3; | |
3 | use Test::More tests => 2; | |
4 | 4 | |
5 | 5 | { |
6 | 6 | package Thingy; |
13 | 13 | required => 1, |
14 | 14 | handles => { 'invoke_callback' => 'execute' }, |
15 | 15 | ); |
16 | ||
17 | has multiplier => ( | |
18 | traits => ['Code'], | |
19 | is => 'ro', | |
20 | isa => 'CodeRef', | |
21 | required => 1, | |
22 | handles => { 'multiply' => 'execute' }, | |
23 | ); | |
24 | 16 | } |
25 | 17 | |
26 | 18 | 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 }); | |
31 | 20 | |
32 | 21 | is($i, 0); |
33 | 22 | $thingy->invoke_callback; |
34 | 23 | is($i, 1); |
35 | is($thingy->multiply(3), 6); |