File Coverage

blib/lib/Specio/Role/Inlinable.pm
Criterion Covered Total %
statement 17 21 80.9
branch n/a
condition n/a
subroutine 7 10 70.0
pod 0 1 0.0
total 24 32 75.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 30     30   174 use warnings;
  30         46  
  30         719  
4 30     30   126  
  30         47  
  30         1029  
5             our $VERSION = '0.48';
6              
7             use Eval::Closure qw( eval_closure );
8 30     30   3497  
  30         10023  
  30         1432  
9             use Role::Tiny;
10 30     30   149  
  30         47  
  30         173  
11             requires '_build_description';
12              
13             {
14             my $attrs = {
15             _inline_generator => {
16             is => 'ro',
17             isa => 'CodeRef',
18             predicate => '_has_inline_generator',
19             init_arg => 'inline_generator',
20             },
21             inline_environment => {
22             is => 'ro',
23             isa => 'HashRef',
24             lazy => 1,
25             init_arg => 'inline_environment',
26             builder => '_build_inline_environment',
27             },
28             _generated_inline_sub => {
29             is => 'ro',
30             isa => 'CodeRef',
31             init_arg => undef,
32             lazy => 1,
33             builder => '_build_generated_inline_sub',
34             },
35             declared_at => {
36             is => 'ro',
37             isa => 'Specio::DeclaredAt',
38             required => 1,
39             },
40             description => {
41             is => 'ro',
42             isa => 'Str',
43             init_arg => undef,
44             lazy => 1,
45             builder => '_build_description',
46             },
47             };
48              
49             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
50             return $attrs;
51             }
52 60     60   132 }
53              
54             # These are here for backwards compatibility. Some other packages that I wrote
55             # may call the private methods.
56              
57             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
58             ## use critic
59              
60 0     0   0 my $self = shift;
61 0     0   0  
62             return $self->_has_inline_generator;
63             }
64              
65 0     0 0 0 my $self = shift;
66              
67 0         0 my $source
68             = 'sub { ' . $self->_inline_generator->( $self, '$_[0]' ) . '}';
69              
70             return eval_closure(
71 1     1   7 source => $source,
72             environment => $self->inline_environment,
73 1         4 description => 'inlined sub for ' . $self->description,
74             );
75             }
76 1         10  
77             return {};
78             }
79              
80             1;
81              
82             # ABSTRACT: A role for things which can be inlined (type constraints and coercions)
83              
84 413     413   2446  
85             =pod
86              
87             =encoding UTF-8
88              
89             =head1 NAME
90              
91             Specio::Role::Inlinable - A role for things which can be inlined (type constraints and coercions)
92              
93             =head1 VERSION
94              
95             version 0.48
96              
97             =head1 DESCRIPTION
98              
99             This role implements a common API for inlinable things, type constraints and
100             coercions. It is fully documented in the relevant classes.
101              
102             =for Pod::Coverage .*
103              
104             =head1 SUPPORT
105              
106             Bugs may be submitted at L<https://github.com/houseabsolute/Specio/issues>.
107              
108             =head1 SOURCE
109              
110             The source code repository for Specio can be found at L<https://github.com/houseabsolute/Specio>.
111              
112             =head1 AUTHOR
113              
114             Dave Rolsky <autarch@urth.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is Copyright (c) 2012 - 2022 by Dave Rolsky.
119              
120             This is free software, licensed under:
121              
122             The Artistic License 2.0 (GPL Compatible)
123              
124             The full text of the license can be found in the
125             F<LICENSE> file included with this distribution.
126              
127             =cut