blib/lib/MoopsX/ListObjects.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.0
CC
2
Cov
0%
import
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.0
1 package MoopsX::ListObjects;
2 {
3 $MoopsX::ListObjects::VERSION = '0.003001';
4 }
5 use strict; use warnings FATAL => 'all';
6  
7 use parent 'Moops';
8 use List::Objects::WithUtils ();
9 use List::Objects::Types ();
10 use Type::Registry ();
11  
12 sub import {
13 my ($class, %params) = @_;
14 push @{ $params{imports} },
15 'List::Objects::Types' => [ -all ],
16 'List::Objects::WithUtils' => [ qw/
17 array immarray array_of immarray_of
18 hash hash_of immhash immhash_of
19 / ],
20 ;
21  
22 my $pkg = caller;
23 Type::Registry->for_class($pkg)->add_types('List::Objects::Types');
24  
25 for my $tname (List::Objects::Types->type_names) {
26 my $reg = Type::Registry->for_class($pkg);
27 $reg->add_type( List::Objects::Types->get_type($tname) )
28 unless $reg->simple_lookup($tname)
29 }
30  
31 @_ = ( $class, %params );
32 goto \&Moops::import
33 }
34  
35 1;
36  
37 =pod
38  
39 =for Pod::Coverage import
40  
41 =head1 NAME
42  
43 MoopsX::ListObjects - Use Moops with List::Objects::WithUtils
44  
45 =head1 SYNOPSIS
46  
47 package My::App;
48 use MoopsX::ListObjects;
49  
50 class Foo {
51 has mylist => (
52 default => sub { array },
53 isa => ArrayObj
54 );
55  
56 has mydata => (
57 default => sub { +{} },
58 isa => HashObj,
59 coerce => 1
60 );
61  
62 method add_items (@items) {
63 $self->mylist->push(@items)
64 }
65  
66 method find_matches (Str $string) {
67 $self->mylist->grep(sub { $_ eq $string })
68 }
69 }
70  
71 my $foo = Foo->new;
72  
73 $foo->add_items(qw/ foo bar baz /);
74  
75 my $matches = $foo->find_matches( 'foo' );
76  
77 =head1 DESCRIPTION
78  
79 Extends Toby Inkster's L<Moops> sugary class building syntax with
80 L<List::Objects::WithUtils> objects.
81  
82 Importing L<MoopsX::ListObjects> is the same as importing L<Moops>, but with
83 all of the objects available from L<List::Objects::WithUtils>, as well as the
84 types and coercions from L<List::Objects::Types>.
85  
86 =head1 SEE ALSO
87  
88 L<Moops>
89  
90 L<List::Objects::WithUtils>
91  
92 L<List::Objects::Types>
93  
94 L<List::Objects::WithUtils::Role::Array>
95  
96 L<List::Objects::WithUtils::Role::Hash>
97  
98 =head1 AUTHOR
99  
100 Jon Portnoy <avenj@cobaltirc.org>
101  
102 =cut