Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / MooseX / LazyRequire / Meta / Attribute / Trait / LazyRequire.pm
1 package MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire;
2 our $VERSION = '0.04';
3
4
5 use Moose::Role;
6 use Carp qw/cluck/;
7 use MooseX::Types::Moose qw/Bool/;
8 use namespace::autoclean;
9
10 has lazy_required => (
11     is       => 'ro',
12     isa      => Bool,
13     required => 1,
14     default  => 0,
15 );
16
17 after _process_options => sub {
18     my ($class, $name, $options) = @_;
19
20     if (exists $options->{lazy_require}) {
21         cluck "deprecated option 'lazy_require' used. use 'lazy_required' instead.";
22         $options->{lazy_required} = delete $options->{lazy_require};
23     }
24
25     return unless $options->{lazy_required};
26
27     Moose->throw_error(
28         "You may not use both a builder or a default and lazy_required for one attribute ($name)",
29         data => $options,
30     ) if $options->{builder};
31
32     $options->{ lazy     } = 1;
33     $options->{ required } = 1;
34     $options->{ default  } = sub {
35         confess "Attribute $name must be provided before calling reader"
36     };
37 };
38
39 package # hide
40     Moose::Meta::Attribute::Custom::Trait::LazyRequire;
41
42 sub register_implementation { 'MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire' }
43
44 1;
45
46 __END__
47
48 =pod
49
50 =head1 NAME
51
52 MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire
53
54 =head1 VERSION
55
56 version 0.04
57
58 =head1 AUTHOR
59
60   Florian Ragwitz <rafl@debian.org>
61
62 =head1 COPYRIGHT AND LICENSE
63
64 This software is copyright (c) 2009 by Florian Ragwitz.
65
66 This is free software; you can redistribute it and/or modify it under
67 the same terms as the Perl 5 programming language system itself.
68
69 =cut 
70
71