File Coverage

blib/lib/MooX/SugarFactory.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition 1 2 50.0
subroutine 10 10 100.0
pod n/a
total 46 47 97.8


line stmt bran cond sub pod time code
1             package MooX::SugarFactory;
2              
3 2     2   21420 use strictures 2;
  2         12  
  2         81  
4 2     2   1063 use Import::Into;
  2         2649  
  2         44  
5 2     2   911 use MooX::BuildClass;
  2         5  
  2         12  
6 2     2   989 use MooX::BuildRole;
  2         9  
  2         14  
7 2     2   1013 use Constructor::SugarLibrary ();
  2         5  
  2         40  
8 2     2   9 use Throwable::SugarFactory::Utils '_getglob';
  2         4  
  2         527  
9              
10             our $VERSION = '0.152690'; # VERSION
11              
12             # ABSTRACT: build a library of syntax-sugared Moo classes
13              
14             #
15             # This file is part of Throwable-SugarFactory
16             #
17             #
18             # Christian Walde has dedicated the work to the Commons by waiving all of his
19             # or her rights to the work worldwide under copyright law and all related or
20             # neighboring legal rights he or she had in the work, to the extent allowable by
21             # law.
22             #
23             # Works under CC0 do not require attribution. When citing the work, you should
24             # not imply endorsement by the author.
25             #
26              
27              
28             sub import {
29 2     2   169 my ( $class ) = @_;
30 2         16 Constructor::SugarLibrary->import::into( 1 );
31 2         13 my $factory = caller;
32 4         12 *{ _getglob $factory, $_ } = $class->_creator_with( $factory, $_ )
33 2         8 for qw( class role );
34             }
35              
36             sub _creator_with {
37 4     4   10 my ( $class, $factory, $type ) = @_;
38 4         6 my $create = \&{ "Build" . ucfirst $type };
  4         15  
39             sub {
40 7     7   28 my ( $spec, @args ) = @_;
41 7         25 my ( $class ) = split /->/, $spec;
42 7   50 7   70 my $build = $factory->can( "BUILDARGS" ) || sub { shift; @_ };
  7         8  
  7         25  
43 7         18 $create->( $class, $build->( $class, @args ) );
44 7         91 $factory->sweeten_meth( $spec );
45 7         31 return;
46 4         17 };
47             }
48              
49             1;
50              
51             __END__