File Coverage

blib/lib/MooX/Role/Parameterized/With.pm
Criterion Covered Total %
statement 24 24 100.0
branch 1 2 50.0
condition 2 3 66.6
subroutine 7 7 100.0
pod n/a
total 34 36 94.4


line stmt bran cond sub pod time code
1             package MooX::Role::Parameterized::With;
2              
3 7     7   402545 use strict;
  7         17  
  7         262  
4 7     7   38 use warnings;
  7         32  
  7         517  
5              
6             our $VERSION = "0.501";
7              
8             # ABSTRACT: MooX::Role::Parameterized:With - dsl to apply roles with composition parameters
9              
10 7     7   46 use Carp qw(carp);
  7         13  
  7         425  
11 7     7   1211 use MooX::Role::Parameterized qw();
  7         17  
  7         545  
12              
13             sub import {
14 14     14   9595 my $target = caller;
15              
16             {
17 14         108 my $orig = $target->can('with');
  14         185  
18 14 50 66     106 carp "will redefine 'with' function"
19             if $orig && $MooX::Role::Parameterized::VERBOSE;
20              
21 7     7   42 no strict 'refs';
  7         13  
  7         283  
22 7     7   35 no warnings 'redefine';
  7         11  
  7         741  
23              
24 14         74 *{ $target . '::with' } =
  14         10761  
25             MooX::Role::Parameterized->build_apply_roles_to_package($orig);
26             }
27             }
28              
29             1;
30              
31             __END__
32              
33             =head1 NAME
34              
35             MooX::Role::Parameterized:With - dsl to apply roles with composition parameters
36              
37             =head1 SYNOPSIS
38              
39             package FooWith;
40              
41             use Moo;
42             use MooX::Role::Parameterized::With; # overrides Moo::with
43              
44             with "Bar" => { # apply parameterized role Bar once
45             attr => 'baz',
46             method => 'run'
47             }, "Other::Role" => [ # apply parameterized role "Other::Role" twice
48             { ... }, # with different parameters
49             { ... },
50             ],
51             "Other::Role" => { ...}, # apply it again
52             "Some::Moo::Role",
53             "Some::Role::Tiny";
54              
55             has foo => ( is => 'ro'); # continue with normal Moo code
56              
57             =head1 DESCRIPTION
58              
59             This B<experimental> package try to offer an easy way to add parametrized roles.
60              
61             Will load and apply L<MooX::Roles::Parameterized> roles, just need use this package
62             with a hash of role => parameters.
63              
64             =head1 AUTHOR
65              
66             Tiago Peczenyj <tiago (dot) peczenyj (at) gmail (dot) com>
67              
68             =head1 BUGS
69              
70             Please report any bugs or feature requests on the bugtracker website