File Coverage

blib/lib/MooseX/AttributeHelpers/Trait/Collection/Bag.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 23 23 100.0


line stmt bran cond sub pod time code
1             package MooseX::AttributeHelpers::Trait::Collection::Bag;
2 22     22   788 use Moose::Role;
  22         29  
  22         129  
3 22     22   79621 use Moose::Util::TypeConstraints;
  22         45  
  22         184  
4              
5             our $VERSION = '0.25';
6              
7 22     22   38981 use MooseX::AttributeHelpers::MethodProvider::Bag;
  22         56  
  22         3294  
8              
9             with 'MooseX::AttributeHelpers::Trait::Collection';
10              
11             has 'method_provider' => (
12             is => 'ro',
13             isa => 'ClassName',
14             predicate => 'has_method_provider',
15             default => 'MooseX::AttributeHelpers::MethodProvider::Bag'
16             );
17              
18             subtype 'Bag' => as 'HashRef[Int]';
19              
20 4     4 1 34 sub helper_type { 'Bag' }
21              
22             before 'process_options_for_provides' => sub {
23             my ($self, $options, $name) = @_;
24              
25             # Set some default attribute options here unless already defined
26             if ((my $type = $self->helper_type) && !exists $options->{isa}){
27             $options->{isa} = $type;
28             }
29            
30             $options->{default} = sub { +{} } unless exists $options->{default};
31             };
32              
33 22     22   131 no Moose::Role;
  22         31  
  22         103  
34 22     22   3700 no Moose::Util::TypeConstraints;
  22         25  
  22         157  
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             MooseX::AttributeHelpers::Trait::Collection::Bag
47              
48             =head1 VERSION
49              
50             version 0.25
51              
52             =head1 SYNOPSIS
53              
54             package Stuff;
55             use Moose;
56             use MooseX::AttributeHelpers;
57            
58             has 'word_histogram' => (
59             metaclass => 'Collection::Bag',
60             is => 'ro',
61             isa => 'Bag', # optional ... as is defalt
62             provides => {
63             'add' => 'add_word',
64             'get' => 'get_count_for',
65             'empty' => 'has_any_words',
66             'count' => 'num_words',
67             'delete' => 'delete_word',
68             }
69             );
70              
71             =head1 DESCRIPTION
72              
73             This module provides a Bag attribute which provides a number of
74             bag-like operations. See L<MooseX::AttributeHelpers::MethodProvider::Bag>
75             for more details.
76              
77             =head1 METHODS
78              
79             =over 4
80              
81             =item B<meta>
82              
83             =item B<method_provider>
84              
85             =item B<has_method_provider>
86              
87             =item B<helper_type>
88              
89             =item B<process_options_for_provides>
90              
91             =back
92              
93             =head1 SUPPORT
94              
95             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers>
96             (or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>).
97              
98             There is also a mailing list available for users of this distribution, at
99             L<http://lists.perl.org/list/moose.html>.
100              
101             There is also an irc channel available for users of this distribution, at
102             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
103              
104             =head1 AUTHOR
105              
106             Stevan Little <stevan@iinteractive.com>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut