File Coverage

blib/lib/Reindeer/Util.pm
Criterion Covered Total %
statement 76 81 93.8
branch n/a
condition n/a
subroutine 28 32 87.5
pod 5 7 71.4
total 109 120 90.8


line stmt bran cond sub pod time code
1             #
2             # This file is part of Reindeer
3             #
4             # This software is Copyright (c) 2011 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 Reindeer::Util;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             $Reindeer::Util::VERSION = '0.018';
13             # ABSTRACT: Common and utility functions for Reindeer
14              
15 11     11   249448 use strict;
  11         75  
  11         276  
16 11     11   35 use warnings;
  11         13  
  11         301  
17              
18 11         90 use Sub::Exporter -setup => {
19             exports => [ qw{ trait_aliases as_is also_list type_libraries } ],
20 11     11   1051 };
  11         16110  
21              
22 11     11   4074 use Class::Load 'load_class';
  11         28384  
  11         594  
23              
24 11     11   4685 use Moose 1.15 ( );
  11         1600687  
  11         372  
25 11     11   5982 use MooseX::AlwaysCoerce 0.16 ( );
  11         783078  
  11         325  
26 11     11   5674 use MooseX::AbstractMethod 0.003 ( );
  11         109148  
  11         379  
27 11     11   6275 use MooseX::AttributeShortcuts 0.017 ( );
  11         2445683  
  11         425  
28 11     11   90 use MooseX::ClassAttribute 0.26 ( );
  11         175  
  11         156  
29 11     11   5276 use MooseX::CurriedDelegation ( );
  11         6821  
  11         257  
30 11     11   3928 use MooseX::LazyRequire 0.07 ( );
  11         80342  
  11         307  
31 11     11   5247 use MooseX::MarkAsMethods 0.14 ( );
  11         62311  
  11         300  
32 11     11   4711 use MooseX::NewDefaults 0.003 ( );
  11         8272  
  11         248  
33 11     11   4041 use MooseX::StrictConstructor 0.19 ( );
  11         123320  
  11         284  
34 11     11   86 use MooseX::Types::Moose 0.31 ( );
  11         221  
  11         176  
35 11     11   44 use MooseX::Types::Common::String 0.001004 ( );
  11         181  
  11         164  
36 11     11   5364 use MooseX::Types::Common::Numeric 0.001004 ( );
  11         426146  
  11         378  
37 11     11   6154 use MooseX::Types::LoadableClass 0.006 ( );
  11         385072  
  11         500  
38 11     11   6973 use MooseX::Types::Path::Class 0.05 ( );
  11         536444  
  11         429  
39 11     11   5805 use MooseX::Types::Tied::Hash::IxHash 0.003 ( );
  11         332259  
  11         439  
40              
41 11     11   6122 use MooseX::Params::Validate 0.016 ( );
  11         463267  
  11         311  
42 11     11   83 use Path::Class 0.24 ( );
  11         167  
  11         240  
43 11     11   42 use Try::Tiny 0.11 ( );
  11         145  
  11         2145  
44              
45             # SlurpyConstructor, Params::Validate
46              
47              
48             sub trait_aliases {
49              
50             # note that merely specifing aliases does not load the packages; Moose
51             # will handle that when (if) the trait is ever used.
52             return (
53 17     17 1 154 [ 'MooseX::AutoDestruct::Trait::Attribute' => 'AutoDestruct' ],
54             [ 'MooseX::MultiInitArg::Trait' => 'MultiInitArg' ],
55             [ 'MooseX::TrackDirty::Attributes::Trait::Attribute' => 'TrackDirty' ],
56             [ 'MooseX::UndefTolerant::Attribute' => 'UndefTolerant' ],
57             [ 'MooseX::CascadeClearing::Role::Meta::Attribute' => 'CascadeClearing' ],
58              
59             # these don't export a trait_alias, so let's create one
60             'MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire',
61              
62             # this one is a little funky, in that it replaces the accessor
63             # metaclass, rather than just applying a trait to it
64             [ 'Moose::Meta::Attribute::Custom::Trait::MergeHashRef' => 'MergeHashRef' ],
65             );
66             }
67              
68             # If an extension doesn't have a trait that's directly loadable, we build subs
69             # to do it here.
70              
71 0     0   0 sub ENV { _lazy('MooseX::Attribute::ENV', 'MooseX::Attribute::ENV' ) }
72 0     0 0 0 sub SetOnce { _lazy('MooseX::SetOnce', 'MooseX::SetOnce::Attribute' ) }
73 0     0 0 0 sub Shortcuts { _lazy('MooseX::AttributeShortcuts', 'MooseX::AttributeShortcuts::Trait::Attribute') }
74              
75 0     0   0 sub _lazy { load_class(shift); shift }
  0         0  
76              
77              
78             sub as_is {
79              
80             return (
81 17     17 1 163 \&ENV,
82             \&SetOnce,
83             \&Shortcuts,
84             );
85             }
86              
87             # Types:
88             # Tied, Perl, IxHash, ENV
89              
90             # Roles:
91             # TraitConstructor, Traits
92              
93              
94             sub also_list {
95              
96 18     18 1 106 return qw{
97             MooseX::AbstractMethod
98             MooseX::AlwaysCoerce
99             MooseX::AttributeShortcuts
100             MooseX::ClassAttribute
101             MooseX::CurriedDelegation
102             MooseX::LazyRequire
103             MooseX::NewDefaults
104             MooseX::StrictConstructor
105             };
106             }
107              
108              
109             sub import_type_libraries {
110 77     77 1 205 my ($class, $opts) = @_;
111              
112             #$_->import({ -into => $opts->{for_class} }, ':all')
113             $_->import($opts, ':all')
114 77         217 for type_libraries();
115              
116 77         1060762 return;
117             }
118              
119              
120             sub type_libraries {
121              
122 79     79 1 772 return qw{
123             MooseX::Types::Moose
124             MooseX::Types::Common::String
125             MooseX::Types::Common::Numeric
126             MooseX::Types::LoadableClass
127             MooseX::Types::Path::Class
128             MooseX::Types::Tied::Hash::IxHash
129             };
130             }
131              
132             !!42;
133              
134             __END__
135              
136             =pod
137              
138             =encoding UTF-8
139              
140             =for :stopwords Chris Weyl
141              
142             =for :stopwords Wishlist flattr flattr'ed gittip gittip'ed
143              
144             =head1 NAME
145              
146             Reindeer::Util - Common and utility functions for Reindeer
147              
148             =head1 VERSION
149              
150             This document describes version 0.018 of Reindeer::Util - released March 28, 2015 as part of Reindeer.
151              
152             =head1 SYNOPSIS
153              
154             =head1 DESCRIPTION
155              
156             This package provides the parts of Reindeer that are common to both Reindeer
157             and Reindeer role. In general, this package contains functions that either
158             return lists for L<Moose::Exporter> or actively import other packages into the
159             namespace of packages invoking Reindeer or Reindeer::Role (e.g. type
160             libraries).
161              
162             =head1 FUNCTIONS
163              
164             =head2 trait_aliases
165              
166             Trait alias definitions for our optional traits.
167              
168             =head2 as_is
169              
170             A list of sugar to export "as_is".
171              
172             =head2 also_list
173              
174             A list of Moose::Exporter based packages that we should also invoke (through
175             Moose::Exporter, that is).
176              
177             =head2 import_type_libraries
178              
179             Import our list of type libraries into a given package.
180              
181             =head2 type_libraries
182              
183             Returns a list of type libraries currently exported by Reindeer.
184              
185             =for Pod::Coverage SetOnce
186             Shortcuts
187              
188             =head1 SEE ALSO
189              
190             Please see those modules/websites for more information related to this module.
191              
192             =over 4
193              
194             =item *
195              
196             L<Reindeer|Reindeer>
197              
198             =back
199              
200             =head1 SOURCE
201              
202             The development version is on github at L<http://https://github.com/RsrchBoy/reindeer>
203             and may be cloned from L<git://https://github.com/RsrchBoy/reindeer.git>
204              
205             =head1 BUGS
206              
207             Please report any bugs or feature requests on the bugtracker website
208             https://github.com/RsrchBoy/reindeer/issues
209              
210             When submitting a bug or request, please include a test-file or a
211             patch to an existing test-file that illustrates the bug or desired
212             feature.
213              
214             =head1 AUTHOR
215              
216             Chris Weyl <cweyl@alumni.drew.edu>
217              
218             =head2 I'm a material boy in a material world
219              
220             =begin html
221              
222             <a href="https://www.gittip.com/RsrchBoy/"><img src="https://raw.githubusercontent.com/gittip/www.gittip.com/master/www/assets/%25version/logo.png" /></a>
223             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
224             <a href="https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Freindeer&title=RsrchBoy's%20CPAN%20Reindeer&tags=%22RsrchBoy's%20Reindeer%20in%20the%20CPAN%22"><img src="http://api.flattr.com/button/flattr-badge-large.png" /></a>
225              
226             =end html
227              
228             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
229             rather B<it is simply a very pleasant surprise>. I largely create and release
230             works like this because I need them or I find it enjoyable; however, don't let
231             that stop you if you feel like it ;)
232              
233             L<Flattr this|https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Freindeer&title=RsrchBoy's%20CPAN%20Reindeer&tags=%22RsrchBoy's%20Reindeer%20in%20the%20CPAN%22>,
234             L<gittip me|https://www.gittip.com/RsrchBoy/>, or indulge my
235             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If you so desire.
236              
237             =head1 COPYRIGHT AND LICENSE
238              
239             This software is Copyright (c) 2011 by Chris Weyl.
240              
241             This is free software, licensed under:
242              
243             The GNU Lesser General Public License, Version 2.1, February 1999
244              
245             =cut