File Coverage

blib/lib/Full/Role.pm
Criterion Covered Total %
statement 28 32 87.5
branch 4 10 40.0
condition 4 11 36.3
subroutine 5 5 100.0
pod n/a
total 41 58 70.6


line stmt bran cond sub pod time code
1             package Full::Role;
2              
3 2     2   520894 use Full::Pragmata qw(:v1);
  2         7  
  2         16  
4 2     2   15 use parent qw(Full::Pragmata);
  2         3  
  2         16  
5              
6             our $VERSION = '1.004'; # VERSION
7             our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8              
9             =encoding utf8
10              
11             =head1 NAME
12              
13             Full::Role - common pragmata for modules which provide an OO rôle
14              
15             =head1 SYNOPSIS
16              
17             package Example::Role;
18             use Full::Role qw(:v1);
19              
20             method example;
21              
22             1;
23              
24             =head3 Method parameter constraints
25              
26             These use L to provide method parameter checks.
27             Note that the C keyword is required, see L for more information.
28              
29             package Example;
30             use Full::Role qw(:v1);
31             extended method example ($v :Checked(Num)) { }
32              
33             =head2 Class features
34              
35             The calling package will be marked as an L rôle, providing the
36             L, L and C keywords, among others.
37              
38             This also makes available a L instance in the C<$log> package variable,
39             and for L support you get C<$tracer> as an L
40             instance.
41              
42             It's very likely that future versions will bring in new functionality or
43             enable/disable a different featureset. This behaviour will be controlled through
44             version tags:
45              
46             use Full::Class qw(:v1);
47              
48             The latest available version is C<:v1>.
49              
50             =cut
51              
52 2     2   289 use Object::Pad;
  2         6  
  2         14  
53 2     2   433 use Object::Pad qw(:experimental(mop));
  2         33  
  2         10  
54              
55 1     1   9 sub import ($called_on, $version, %args) {
  1         2  
  1         3  
  1         3  
  1         2  
56 1         2 my $class = __PACKAGE__;
57 1   33     9 my $pkg = $args{target} // caller(0);
58              
59 1         9 $class->next::method($version, target => $pkg);
60 1 50 33     13 if(my $class = $args{class} // $pkg) {
61 1         7 Object::Pad->import_into($pkg, ":experimental(init_expr mop custom_field_attr)");
62              
63 1   50     179 my $method = 'begin_' . ($args{type} || 'role');
64 1 50       4 Module::Load::load($args{extends}) if $args{extends};
65             my $meta = Object::Pad::MOP::Class->$method(
66             $class,
67             (
68             $args{extends}
69             ? (extends => $args{extends})
70 1 50       12 : ()
71             ),
72             );
73 1 50 33     130 $args{does} = [ $args{does} // () ] unless ref $args{does};
74 1         3 for my $role ($args{does}->@*) {
75 0 0       0 Module::Load::load($role) unless eval { Object::Pad::MOP::Class->for_class($role) };
  0         0  
76 0         0 $meta->add_role($role);
77             }
78 1         310 return $meta;
79             }
80 0           return $pkg;
81             }
82              
83             1;
84              
85             __END__