File Coverage

blib/lib/MooseX/Extended/Custom.pm
Criterion Covered Total %
statement 31 31 100.0
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 0 1 0.0
total 41 43 95.3


line stmt bran cond sub pod time code
1             package MooseX::Extended::Custom;
2              
3             # ABSTRACT: Build a custom Moose, just for you.
4              
5 1     1   189653 use 5.20.0;
  1         13  
6 1     1   5 use strict;
  1         2  
  1         20  
7 1     1   4 use warnings;
  1         2  
  1         23  
8 1     1   447 use true;
  1         2925  
  1         6  
9 1         79 use MooseX::Extended::Core qw(
10             _enabled_features
11             _disabled_warnings
12 1     1   1693 );
  1         4  
13 1     1   511 use MooseX::Extended ();
  1         5  
  1         30  
14 1     1   6 use namespace::autoclean;
  1         4  
  1         7  
15              
16             our $VERSION = '0.35';
17              
18             sub import {
19 1     1   10 my @caller = caller(0);
20 1         20 my $custom_moose = $caller[0]; # this is our custom Moose definition
21 1 50       14 true->import::into($custom_moose) unless $caller[1] =~ /^\(eval/;
22 1         1382 strict->import::into($custom_moose);
23 1         220 warnings->import::into($custom_moose);
24 1         173 namespace::autoclean->import::into($custom_moose);
25 1         218 feature->import( _enabled_features() );
26 1         5 warnings->unimport(_disabled_warnings);
27             }
28              
29             sub create {
30 2     2 0 3853 my ( $class, %args ) = @_;
31 2         15 my $target_class = caller(1); # this is the class consuming our custom Moose
32 2         58 MooseX::Extended->import(
33             %args,
34             call_level => 1,
35             for_class => $target_class,
36             );
37             }
38              
39             1;
40              
41             __END__
42              
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             MooseX::Extended::Custom - Build a custom Moose, just for you.
50              
51             =head1 VERSION
52              
53             version 0.35
54              
55             =head1 SYNOPSIS
56              
57             Define your own version of L<MooseX::Extended>:
58              
59             package My::Moose {
60             use MooseX::Extended::Custom;
61              
62             sub import {
63             my ( $class, %args ) = @_;
64             MooseX::Extended::Custom->create(
65             excludes => [qw/ StrictConstructor c3 /],
66             includes => ['multi'],
67             %args # you need this to allow customization of your customization
68             );
69             }
70             }
71              
72             # no need for a true value
73              
74             And then use it:
75              
76             package Some::Class {
77             use My::Moose types => [qw/ArrayRef Num/];
78              
79             param numbers ( isa => ArrayRef[Num] );
80              
81             multi sub foo ($self) { ... }
82             multi sub foo ($self, $bar) { ... }
83             }
84              
85             =head1 DESCRIPTION
86              
87             I hate boilerplate, so let's get rid of it. Let's say you don't want L<namespace::autoclean> or
88             C<carp>, but you do want C<multi>. Plus, you have custom versions of C<carp> and C<croak>:
89              
90             package Some::Class {
91             use MooseX::Extended
92             excludes => [qw/ autoclean carp /],
93             includes => ['multi'];
94             use My::Carp q(carp croak);
95              
96             ... my code here
97             }
98              
99             You probably get tired of typing that every time. Now you don't have to.
100              
101             package My::Moose {
102             use MooseX::Extended::Custom;
103             use My::Carp ();
104             use Import::Into;
105              
106             sub import {
107             my ( $class, %args ) = @_;
108             my $target_class = caller;
109             MooseX::Extended::Custom->create(
110             excludes => [qw/ autoclean carp /],
111             includes => ['multi'],
112             %args # you need this to allow customization of your customization
113             );
114             My::Carp->import::into($target_class, qw(carp croak));
115             }
116             }
117              
118             And then when you use C<My::Moose>, that's all set up for you.
119              
120             If you need to change this on a "per class" basis:
121              
122             use My::Moose
123             excludes => ['carp'],
124             types => [qw/ArrayRef Num/];
125              
126             The above changes your C<excludes> and adds C<types>, but doesn't change your C<includes>.
127              
128             =head1 AUTHOR
129              
130             Curtis "Ovid" Poe <curtis.poe@gmail.com>
131              
132             =head1 COPYRIGHT AND LICENSE
133              
134             This software is Copyright (c) 2022 by Curtis "Ovid" Poe.
135              
136             This is free software, licensed under:
137              
138             The Artistic License 2.0 (GPL Compatible)
139              
140             =cut