MooseX::Types::Moose::MutualCoercion - Mutual coercions for common type constraints of Moose
This document describes MooseX::Types::Moose::MutualCoercion version 0.04.
0.04
{ package Foo; use Moose; use MooseX::Types::Moose::MutualCoercion qw(StrToArrayRef ArrayRefToHashKeys); has 'thingies' => (is => 'rw', isa => StrToArrayRef, coerce => 1); has 'lookup_table' => (is => 'rw', isa => ArrayRefToHashKeys, coerce => 1); 1; } my $foo = Foo->new( thingies => 'bar' ); print $foo->thingies->[0]; # 'bar' $foo->lookup_table( [qw(baz qux)] ); print 'eureka!' # 'eureka!' if grep { exists $foo->lookup_table->{$_}; } qw(foo bar baz);
Much of the MooseX::Types::Moose::MutualCoercion documentation has been translated into other language(s).
MooseX::Types::Moose::MutualCoercion (This document)
MooseX::Types::Moose::MutualCoercion::JA
This module packages several Moose::Util::TypeConstraints with coercions, designed to mutually coerce with the built-in and common types known to Moose.
NOTE: These constraints are not exported by default but you can request them in an import list like this:
use MooseX::Types::Moose::MutualCoercion qw(NumToInt ScalarRefToStr);
Int
NumToInt
A subtype of Int. If you turned coerce on, Num will become integer. For example, 3.14 will be converted into 3.
coerce
Num
3.14
3
Str
ScalarRefToStr
A subtype of Str. If you turned coerce on, ScalarRef[Str] will become dereferenced string. For example, \do{'foo'} will be converted into foo.
ScalarRef[Str]
\do{'foo'}
foo
ArrayRefToLines
A subtype of Str. If you turned coerce on, all elements of ArrayRef[Str] will be joined by $/. For example, [qw(foo bar baz)] will be converted into foo\nbar\nbaz\n.
ArrayRef[Str]
$/
[qw(foo bar baz)]
foo\nbar\nbaz\n
NOTE: Also adds $/ to the last element.
ClassName
StrToClassName
CAVEAT: This type constraint and coercion is DEPRECATED. Please use MooseX::Types::LoadableClass's LodableClass instead of it. In addition, MooseX::Types::LoadableClass also has LodableRole.
A subtype of ClassName. If you turned coerce on, NonEmptyStr, provided by MooseX::Types::Common::String, will be treated as a class name. When it is not already loaded, it will be loaded by Class::Load::load_class().
NonEmptyStr
ScalarRef
StrToScalarRef
A subtype of ScalarRef[Str]. If you turned coerce on, Str will be referenced. For example, foo will be converted into \do{'foo'}.
ArrayRef
StrToArrayRef
A subtype of ArrayRef. If you turned coerce on, Str will be assigned for the first element of an array reference. For example, foo will be converted into [qw(foo)].
[qw(foo)]
LinesToArrayRef
A subtype of ArrayRef. If you turned coerce on, Str will be split by $/ and will be assigned for each element of an array reference. For example, foo\nbar\nbaz\n will be converted into ["foo\n", "bar\n", "baz\n"].
["foo\n", "bar\n", "baz\n"]
NOTE: $/ was not removed.
HashRefToArrayRef
A subtype of ArrayRef. If you turned coerce on, HashRef will be flattened as an array reference. For example, {foo => 0, bar => 1} will be converted into [qw(bar 1 foo 0)].
HashRef
{foo => 0, bar => 1}
[qw(bar 1 foo 0)]
NOTE: Order of keys/values is the same as lexically sorted keys.
HashKeysToArrayRef
A subtype of ArrayRef. If you turned coerce on, list of lexically sorted keys of HashRef will become an array reference. For example, {foo => 0, bar => 1} will be converted into [qw(bar foo)].
[qw(bar foo)]
HashValuesToArrayRef
A subtype of ArrayRef. If you turned coerce on, list of values of HashRef will become an array reference. For example, {foo => 0, bar => 1} will be converted into [qw(1 0)].
[qw(1 0)]
NOTE: Order of values is the same as lexically sorted keys.
OddArrayRef
A subtype of ArrayRef, that must have odd elements. If you turned coerce on, ArrayRef, that has even elements, will be pushed undef as the last element. For example, [qw(foo bar)] will be converted into [qw(foo bar), undef].
undef
[qw(foo bar)]
[qw(foo bar), undef]
EvenArrayRef
A subtype of ArrayRef, that must have even elements. If you turned coerce on, ArrayRef, that has odd elements, will be pushed undef as the last element. For example, [qw(foo)] will be converted into [qw(foo), undef].
[qw(foo), undef]
ArrayRefToHashRef
A subtype of HashRef. If you turned coerce on, all elements of EvenArrayRef will be substituted for a hash reference. For example, [qw(foo 0 bar 1)] will be converted into {foo => 0, bar => 1}.
[qw(foo 0 bar 1)]
ArrayRefToHashKeys
A subtype of HashRef. If you turned coerce on, all elements of ArrayRef will be substituted for keys of a hash reference. For example, [qw(foo bar baz)] will be converted into {foo => undef, bar => undef, baz => undef}.
{foo => undef, bar => undef, baz => undef}
RegexpRef
ArrayRefToRegexpRef
A subtype of RegexpRef. If you turned coerce on, all elements of ArrayRef will be joined with | (the meta character for alternation) and will become a regular expression reference. For example, [qw(foo bar baz)] will be converted into qr{foo|bar|baz}.
|
qr{foo|bar|baz}
NOTE: If Regexp::Assemble can be loaded dynamically, namely at runtime, a regular expression reference will be built with this module. For example, [qw(foo bar baz)] will be converted into qr{(?:ba[rz]|foo)}.
qr{(?:ba[rz]|foo)}
Moose::Manual::Types
MooseX::Types
MooseX::Types::Moose
MooseX::Types::LoadableClass
MooseX::Types::Common
About special variable $/ ($RS, $INPUT_RECORD_SEPARATOR).
$RS
$INPUT_RECORD_SEPARATOR
perlvar
None reported.
No bugs have been reported.
Please report any found bugs, feature requests, and ideas for improvements to <bug-moosex-types-moose-mutualcoercion at rt.cpan.org>, or through the web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=MooseX-Types-Moose-MutualCoercion. I will be notified, and then you'll automatically be notified of progress on your bugs/requests as I make changes.
<bug-moosex-types-moose-mutualcoercion at rt.cpan.org>
When reporting bugs, if possible, please add as small a sample as you can make of the code that produces the bug. And of course, suggestions and patches are welcome.
You can find documentation for this module with the perldoc command.
perldoc
% perldoc MooseX::Types::Moose::MutualCoercion
You can also find the Japanese edition of documentation for this module with the perldocjp command from Pod::PerldocJp.
perldocjp
% perldocjp MooseX::Types::Moose::MutualCoercion::JA
You can also look for information at:
http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Moose-MutualCoercion
http://annocpan.org/dist/MooseX-Types-Moose-MutualCoercion
http://search.cpan.org/dist/MooseX-Types-Moose-MutualCoercion
http://cpanratings.perl.org/dist/MooseX-Types-Moose-MutualCoercion
This module is maintained using Git. You can get the latest version from git://github.com/gardejo/p5-moosex-types-moose-mutualcoercion.git.
More tests
<moriya at cpan dot org>, http://gardejo.org/
<moriya at cpan dot org>
Copyright (c) 2010 MORIYA Masaki, alias Gardejo
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlgpl and perlartistic.
The full text of the license can be found in the LICENSE file included with this distribution.
To install MooseX::Types::Moose::MutualCoercion, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::Moose::MutualCoercion
CPAN shell
perl -MCPAN -e shell install MooseX::Types::Moose::MutualCoercion
For more information on module installation, please visit the detailed CPAN module installation guide.