<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Specio::Role::Inlinable;

use strict;
use warnings;

our $VERSION = '0.42';

use Eval::Closure qw( eval_closure );

use Role::Tiny;

requires '_build_description';

{
    my $attrs = {
        _inline_generator =&gt; {
            is        =&gt; 'ro',
            isa       =&gt; 'CodeRef',
            predicate =&gt; '_has_inline_generator',
            init_arg  =&gt; 'inline_generator',
        },
        inline_environment =&gt; {
            is       =&gt; 'ro',
            isa      =&gt; 'HashRef',
            lazy     =&gt; 1,
            init_arg =&gt; 'inline_environment',
            builder  =&gt; '_build_inline_environment',
        },
        _generated_inline_sub =&gt; {
            is       =&gt; 'ro',
            isa      =&gt; 'CodeRef',
            init_arg =&gt; undef,
            lazy     =&gt; 1,
            builder  =&gt; '_build_generated_inline_sub',
        },
        declared_at =&gt; {
            is       =&gt; 'ro',
            isa      =&gt; 'Specio::DeclaredAt',
            required =&gt; 1,
        },
        description =&gt; {
            is       =&gt; 'ro',
            isa      =&gt; 'Str',
            init_arg =&gt; undef,
            lazy     =&gt; 1,
            builder  =&gt; '_build_description',
        },
    };

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

# These are here for backwards compatibility. Some other packages that I wrote
# may call the private methods.

## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
sub _description        { $_[0]-&gt;description }
sub _inline_environment { $_[0]-&gt;inline_environment }
## use critic

sub can_be_inlined {
    my $self = shift;

    return $self-&gt;_has_inline_generator;
}

sub _build_generated_inline_sub {
    my $self = shift;

    my $source
        = 'sub { ' . $self-&gt;_inline_generator-&gt;( $self, '$_[0]' ) . '}';

    return eval_closure(
        source      =&gt; $source,
        environment =&gt; $self-&gt;inline_environment,
        description =&gt; 'inlined sub for ' . $self-&gt;description,
    );
}

sub _build_inline_environment {
    return {};
}

1;

# ABSTRACT: A role for things which can be inlined (type constraints and coercions)

__END__

=pod

=encoding UTF-8

=head1 NAME

Specio::Role::Inlinable - A role for things which can be inlined (type constraints and coercions)

=head1 VERSION

version 0.42

=head1 DESCRIPTION

This role implements a common API for inlinable things, type constraints and
coercions. It is fully documented in the relevant classes.

=for Pod::Coverage .*

=head1 SUPPORT

Bugs may be submitted at L&lt;https://github.com/houseabsolute/Specio/issues&gt;.

I am also usually active on IRC as 'autarch' on C&lt;irc://irc.perl.org&gt;.

=head1 SOURCE

The source code repository for Specio can be found at L&lt;https://github.com/houseabsolute/Specio&gt;.

=head1 AUTHOR

Dave Rolsky &lt;autarch@urth.org&gt;

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 - 2017 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the
F&lt;LICENSE&gt; file included with this distribution.

=cut
</pre></body></html>