File Coverage

blib/lib/MooseX/Util.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 6 66.6
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             #
2             # This file is part of MooseX-Util
3             #
4             # This software is Copyright (c) 2012 by Chris Weyl.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package MooseX::Util;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             # git description: 0.005-4-gcb0aacd
13             $MooseX::Util::VERSION = '0.006';
14              
15             # ABSTRACT: Moose::Util extensions
16              
17 3     3   347767 use strict;
  3         4  
  3         70  
18 3     3   10 use warnings;
  3         3  
  3         64  
19              
20 3     3   715 use parent 'Moose::Util';
  3         471  
  3         14  
21              
22 3         34 use Sub::Exporter::Progressive -setup => {
23                 exports => [
24                     qw{
25             add_method_modifier
26             apply_all_roles
27             does_role
28             english_list
29             ensure_all_roles
30             find_meta
31             get_all_attribute_values
32             get_all_init_args
33             is_role
34             meta_attribute_alias
35             meta_class_alias
36             resolve_metaclass_alias
37             resolve_metatrait_alias
38             search_class_by_role
39             throw_exception
40             with_traits
41             },
42              
43             # and our own...
44                     qw{
45             is_private
46             },
47                 ],
48                 groups => { default => [ ':all' ] },
49 3     3   175940 };
  3         5  
50              
51 3     3   444 use Carp 'confess';
  3         4  
  3         127  
52 3     3   1246 use MooseX::Util::Meta::Class;
  3         39  
  3         11  
53              
54              
55             # TODO allow with_traits() to be curried with different class metaclasses?
56              
57             sub with_traits {
58 2     2 1 6143     my ($class, @roles) = @_;
59 2 50       6     return $class unless @roles;
60 2         13     return MooseX::Util::Meta::Class->create_anon_class(
61                     superclasses => [$class],
62                     roles => \@roles,
63                     cache => 1,
64                 )->name;
65             }
66              
67              
68             sub is_private($) {
69 2     2 1 78     my ($name) = @_;
70              
71 2 50       5     confess 'is_private() must be called with a name to test!'
72                     unless $name;
73              
74 2 100       8     return 1 if $name =~ /^_/;
75 1         3     return;
76             }
77              
78 4     4 1 732 sub find_meta { goto \&Moose::Util::find_meta }
79              
80             !!42;
81              
82             __END__
83            
84             =pod
85            
86             =encoding UTF-8
87            
88             =for :stopwords Chris Weyl
89            
90             =for :stopwords Wishlist flattr flattr'ed gittip gittip'ed
91            
92             =head1 NAME
93            
94             MooseX::Util - Moose::Util extensions
95            
96             =head1 VERSION
97            
98             This document describes version 0.006 of MooseX::Util - released June 26, 2015 as part of MooseX-Util.
99            
100             =head1 SYNOPSIS
101            
102             use MooseX::Util qw{ ensure_all_roles with_traits };
103            
104             # profit!
105            
106             =head1 DESCRIPTION
107            
108             This is a utility module that handles all of the same functions that
109             L<Moose::Util> handles. In fact, most of the functions exported by this
110             package are simply re-exports from L<Moose::Util>, so you're recommended to
111             read the documentation of that module for a comprehensive view.
112            
113             However.
114            
115             We've re-implemented a number of the functions our parent provides, for a
116             variety of reasons. Those functions are documented here.
117            
118             =head1 FUNCTIONS
119            
120             =head2 with_traits(<classname> => (<trait1>, ... ))
121            
122             Given a class and one or more traits, we construct an anonymous class that is
123             a subclass of the given class and consumes the traits given. This is exactly
124             the same as L<Moose::Util/with_traits>, except that we use
125             L<MooseX::Util::Meta::Class/create_anon_class> to construct the anonymous
126             class, rather than L<Moose::Meta::Class/create_anon_class> directly.
127            
128             Essentially, this means that when we do:
129            
130             my $anon_class_name = with_traits('Zombie::Catcher', 'SomeTrait');
131            
132             For $anon_class_name we get:
133            
134             Zombie::Catcher::__ANON__::SERIAL::1
135            
136             Rather than:
137            
138             Moose::Meta::Class::__ANON__::SERIAL::1
139            
140             This is nice because we have an idea of where the first anonymous class came
141             from, whereas the second one could could be from anywhere.
142            
143             =head2 is_private
144            
145             # true if "private"
146             ... if is_private('_some_name');
147            
148             Ofttimes we need to determine if a name is considered "private" or not. By convention,
149             method, attribute, and other names are considered private if their first character is
150             an underscore.
151            
152             While trivial to test for, this allows us to centralize the tests in one place.
153            
154             =for Pod::Coverage find_meta
155            
156             =head1 SEE ALSO
157            
158             Please see those modules/websites for more information related to this module.
159            
160             =over 4
161            
162             =item *
163            
164             L<Moose::Util>
165            
166             =back
167            
168             =head1 BUGS
169            
170             Please report any bugs or feature requests on the bugtracker website
171             https://github.com/RsrchBoy/moosex-util/issues
172            
173             When submitting a bug or request, please include a test-file or a
174             patch to an existing test-file that illustrates the bug or desired
175             feature.
176            
177             =head1 AUTHOR
178            
179             Chris Weyl <cweyl@alumni.drew.edu>
180            
181             =head2 I'm a material boy in a material world
182            
183             =begin html
184            
185             <a href="https://gratipay.com/RsrchBoy/"><img src="http://img.shields.io/gratipay/RsrchBoy.svg" /></a>
186             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
187             <a href="https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fmoosex-util&title=RsrchBoy's%20CPAN%20MooseX-Util&tags=%22RsrchBoy's%20MooseX-Util%20in%20the%20CPAN%22"><img src="http://api.flattr.com/button/flattr-badge-large.png" /></a>
188            
189             =end html
190            
191             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
192             rather B<it is simply a very pleasant surprise>. I largely create and release
193             works like this because I need them or I find it enjoyable; however, don't let
194             that stop you if you feel like it ;)
195            
196             L<Flattr|https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fmoosex-util&title=RsrchBoy's%20CPAN%20MooseX-Util&tags=%22RsrchBoy's%20MooseX-Util%20in%20the%20CPAN%22>,
197             L<Gratipay|https://gratipay.com/RsrchBoy/>, or indulge my
198             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If and *only* if you so desire.
199            
200             =head1 COPYRIGHT AND LICENSE
201            
202             This software is Copyright (c) 2012 by Chris Weyl.
203            
204             This is free software, licensed under:
205            
206             The GNU Lesser General Public License, Version 2.1, February 1999
207            
208             =cut
209