0
  
   M�236ÅÂì  ì    M<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>
  ?   Oˆl–Ü4ý(©–Ú”%åÆEp)‹Fÿ�þDZY²„E}æÚ+àóðƒxM5ï_ˆI|¥�+V[(Äî  4    Opackage Specio::Coercion;

use strict;
use warnings;

our $VERSION = '0.48';

use Specio::OO;

use Role::Tiny::With;

use Specio::Role::Inlinable;
with 'Specio::Role::Inlinable';

{
    ## no critic (Subroutines::ProtectPrivateSubs)
    my $role_attrs = Specio::Role::Inlinable::_attrs();
    ## use critic

    my $attrs = {
        %{$role_attrs},
        from => {
            does     => 'Specio::Constraint::Role::Interface',
            required => 1,
        },
        to => {
            does     => 'Specio::Constraint::Role::Interface',
            required => 1,
            weak_ref => 1,
        },
        _coercion => {
            isa       => 'CodeRef',
            predicate => '_has_coercion',
            init_arg  => 'coercion',
        },
        _optimized_coercion => {
            isa      => 'CodeRef',
            init_arg => undef,
            lazy     => 1,
            builder  => '_build_optimized_coercion',
        },
    };

    ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
    sub _attrs {
        return $attrs;
    }
}

sub BUILD {
    my $self = shift;

    die
        'A type coercion should have either a coercion or inline_generator parameter, not both'
        if $self->_has_coercion && $self->_has_inline_generator;

    die
        'A type coercion must have either a coercion or inline_generator parameter'
        unless $self->_has_coercion || $self->_has_inline_generator;

    return;
}

sub coerce {
    my $self  = shift;
    my $value = shift;

    return $self->_optimized_coercion->($value);
}

sub inline_coercion {
    my $self = shift;

    return $self->_inline_generator->( $self, @_ );
}

sub _build_optimized_coercion {
    my $self = shift;

    if ( $self->_has_inline_generator ) {
        return $self->_generated_inline_sub;
    }
    else {
        return $self->_coercion;
    }
}

sub can_be_inlined {
    my $self = shift;

    return $self->_has_inline_generator && $self->from->can_be_inlined;
}

sub _build_description {
    my $self = shift;

    my $from_name
        = defined $self->from->name ? $self->from->name : 'anonymous type';
    my $to_name
        = defined $self->to->name ? $self->to->name : 'anonymous type';
    my $desc = "coercion from $from_name to $to_name";

    $desc .= q{ } . $self->declared_at->description;

    return $desc;
}

sub clone_with_new_to {
    my $self   = shift;
    my $new_to = shift;

    my $from = $self->from;

    local $self->{from} = undef;
    local $self->{to}   = undef;

    my $clone = $self->clone;

    $clone->{from} = $from;
    $clone->{to}   = $new_to;

    return $clone;
}

__PACKAGE__->_ooify;

1;

# ABSTRACT: A class representing a coercion from one type to another

__END__

=pod

=encoding UTF-8

=head1 NAME

Specio::Coercion - A class representing a coercion from one type to another

=head1 VERSION

version 0.48

=head1 SYNOPSIS

    my $coercion = $type->coercion_from_type('Int');

    my $new_value = $coercion->coerce_value(42);

    if ( $coercion->can_be_inlined() ) {
        my $code = $coercion->inline_coercion('$_[0]');
    }

=head1 DESCRIPTION

This class represents a coercion from one type to another. Internally, a
coercion is a piece of code that takes a value of one type returns a new value
of a new type. For example, a coercion from c<Num> to C<Int> might round a
number to its nearest integer and return that integer.

Coercions can be implemented either as a simple subroutine reference or as an
inline generator subroutine. Using an inline generator is faster but more
complicated.

=for Pod::Coverage BUILD clone_with_new_to

=head1 API

This class provides the following methods.

=head2 Specio::Coercion->new( ... )

This method creates a new coercion objec