File Coverage

blib/lib/Bolts/Artifact/Thunk.pm
Criterion Covered Total %
statement 4 4 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 7 7 100.0


line stmt bran cond sub pod time code
1             package Bolts::Artifact::Thunk;
2             $Bolts::Artifact::Thunk::VERSION = '0.143171';
3             # ABSTRACT: Simplified artifact implementation
4              
5 11     11   52 use Moose;
  11         34  
  11         93  
6              
7              
8             has thunk => (
9             is => 'ro',
10             isa => 'CodeRef',
11             traits => [ 'Code' ],
12             handles => {
13             'get' => 'execute_method',
14             },
15             );
16              
17              
18             # TODO Fix this. Make it do something rather than ignore the check.
19 77     77 1 103 sub such_that { }
20              
21             with 'Bolts::Role::Artifact';
22              
23             __PACKAGE__->meta->make_immutable;
24              
25             __END__
26              
27             =pod
28              
29             =encoding UTF-8
30              
31             =head1 NAME
32              
33             Bolts::Artifact::Thunk - Simplified artifact implementation
34              
35             =head1 VERSION
36              
37             version 0.143171
38              
39             =head1 SYNOPSIS
40              
41             use Bolts;
42              
43             my $artifact = Bolts::Artifact::Thunk->new(
44             thunk => sub {
45             my ($artifact, $bag, %parameters) = @_;
46             return MyApp::Thing->new(%parameters);
47             },
48             );
49              
50             =head1 DESCRIPTION
51              
52             This provides a greatly simplified implementation of L<Bolts::Role::Artifact>. This skips out on all of the main features of Bolts by just boiling the artifact definition down to the simplest possible form. There are no blueprints, no scope, no injection, just a thunk that does the work.
53              
54             This is handy for cases where a full-blown artifact implementation is tedious or impossible, particularly when bootstrapping L<Bolts::Meta::Locator>.
55              
56             It may also be used when you just need a shortcut or optimization. That said, you will probably regret any extensive use of this. (I mean, really, why bother with the Bolt framework if you just short-circuit major bits down to this? You could just implement something simpler and probably faster.)
57              
58             =head1 ROLES
59              
60             =over
61              
62             =item *
63              
64             L<Bolts::Role::Artifact>
65              
66             =back
67              
68             =head1 ATTRIBUTES
69              
70             =head2 thunk
71              
72             This is the code reference used to construct the artifact. It will be called every time the artifact is resolved.
73              
74             =head1 METHODS
75              
76             =head2 get
77              
78             This is implemented using the C<execute_method> of L<Moose::Meta::Attribute::Trait::Native::Code> on L</thunk>.
79              
80             =head2 such_that
81              
82             Not implemented.
83              
84             B<Caution:> In the future, this will probably be implemented.
85              
86             =head1 AUTHOR
87              
88             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2014 by Qubling Software LLC.
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut