File Coverage

blib/lib/MooseX/LazyRequire/Meta/Attribute/Trait/LazyRequire.pm
Criterion Covered Total %
statement 9 10 90.0
branch n/a
condition n/a
subroutine 3 4 75.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             package MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire;
2             # ABSTRACT: Attribute trait to make getters fail on unset attributes
3             $MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire::VERSION = '0.11';
4 3     3   291879 use Moose::Role;
  3         14676  
  3         17  
5 3     3   17792 use Carp qw/cluck/;
  3         8  
  3         179  
6 3     3   2026 use namespace::autoclean;
  3         3079  
  3         21  
7              
8             has lazy_required => (
9             is => 'ro',
10             isa => 'Bool',
11             default => 0,
12             );
13              
14             after _process_options => sub {
15             my ($class, $name, $options) = @_;
16              
17             if (exists $options->{lazy_require}) {
18             cluck "deprecated option 'lazy_require' used. use 'lazy_required' instead.";
19             $options->{lazy_required} = delete $options->{lazy_require};
20             }
21              
22             return unless $options->{lazy_required};
23              
24             # lazy_required + default or builder doesn't make sense because if there
25             # is a default/builder, the reader will always be able to return a value.
26             Moose->throw_error(
27             "You may not use both a builder or a default and lazy_required for one attribute ($name)",
28             data => $options,
29             ) if $options->{builder} or $options->{default};
30              
31             $options->{ lazy } = 1;
32             $options->{ required } = 1;
33             $options->{ default } = sub {
34             confess "Attribute '$name' must be provided before calling reader"
35             };
36             };
37              
38             package # hide
39             Moose::Meta::Attribute::Custom::Trait::LazyRequire;
40              
41 0     0     sub register_implementation { 'MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire' }
42              
43             1;
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire - Attribute trait to make getters fail on unset attributes
54              
55             =head1 VERSION
56              
57             version 0.11
58              
59             =head1 AUTHORS
60              
61             =over 4
62              
63             =item *
64              
65             Florian Ragwitz <rafl@debian.org>
66              
67             =item *
68              
69             Dave Rolsky <autarch@urth.org>
70              
71             =back
72              
73             =head1 COPYRIGHT AND LICENSE
74              
75             This software is copyright (c) 2009 by Florian Ragwitz.
76              
77             This is free software; you can redistribute it and/or modify it under
78             the same terms as the Perl 5 programming language system itself.
79              
80             =cut