+our $VERSION = '0.03';
+
+=head1 SYNOPSIS
+
+ # The target class of the autocoercion (cannot be changed)
+ {
+ package X;
+ use Mouse;
+ has 'id' => (
+ is => 'ro',
+ isa => 'Int',
+ );
+ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce;
+ use Mouse::Util::TypeConstraints;
+ register_type_constraint(
+ LaTeX::TikZ::Meta::TypeConstraint::Autocoerce->new(
+ name => 'X::Autocoerce',
+ target => find_type_constraint(__PACKAGE__),
+ mapper => sub { join '::', __PACKAGE__, 'From', $_[1] },
+ );
+ );
+ __PACKAGE__->meta->make_immutable;
+ }
+
+ # The class that does the coercion (cannot be changed)
+ {
+ package Y;
+ use Mouse;
+ has 'x' => (
+ is => 'ro',
+ isa => 'X::Autocoerce',
+ coerce => 1,
+ handles => [ 'id' ],
+ );
+ __PACKAGE__->meta->make_immutable;
+ }
+
+ # Another class the user wants to use instead of X (cannot be changed)
+ {
+ package Z;
+ use Mouse;
+ has 'id' => (
+ is => 'ro',
+ isa => 'Num',
+ );
+ __PACKAGE__->meta->make_immutable;
+ }
+
+ # The autocoercion class, defined by the user in X/From/Z.pm
+ {
+ package X::From::Z;
+ use Mouse::Util::TypeConstraints;
+ coerce 'X::Autocoerce'
+ => from 'Z'
+ => via { X->new(id => int $_->id) };
+ }
+
+ my $z = Z->new(id => 123);
+ my $y = Y->new(x => $z);
+ print $y->id; # 123
+
+=head1 DESCRIPTION
+
+When a type coercion is attempted, this type constraint metaclass tries to autoload a specific module which is supposed to contain the actual coercion code.
+This allows you to declare types that can be replaced (through coercion) at the end user's discretion.
+
+It only supports L<Mouse> currently.
+
+Note that you will need L<Mouse::Util::TypeConstraints/register_type_constraint> to install this type constraint, which is only available starting L<Mouse> C<0.63>.
+
+=cut
+
+use Scalar::Util qw<blessed>;