blib/lib/UR/Role.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 15 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 123 SCAR 34.0
CC
5
Cov
0%
_define_role
30.0
define
2.0
BEGIN
2.0
CRAP 30.0
1 package UR::Role;
2  
3 use strict;
4 use warnings;
5  
6 use UR;
7 use UR::Object::Type::InternalAPI;
8 use UR::Util;
9 use UR::AttributeHandlers;
10  
11 use UR::Role::Param;
12 use UR::Role::Prototype;
13 use UR::Role::PrototypeWithParams;
14 use UR::Role::Instance;
15  
16 use Scalar::Util qw(blessed);
17 use List::MoreUtils qw(any);
18 use Sub::Install;
19 use Sub::Name;
20 use Carp;
21 our @CARP_NOT = qw(UR::Object::Type);
22  
23 use Exporter qw(import);
24 our @EXPORT_OK = qw(before after around);
25  
26 our $VERSION = "0.46"; # UR $VERSION;;
27  
28 Class::Autouse->sugar(\&_define_role);
29  
30 sub define {
31 my $class = shift;
32 UR::Role::Prototype->define(@_);
33 }
34  
35 sub _define_role {
36 my($role_name, $func, @params) = @_;
37  
38 if (defined($func) and $func eq "role" and @params > 1 and $role_name ne "UR::Role") {
39 my @role_params;
40 if (@params == 2 and ref($params[1]) eq 'HASH') {
41 @role_params = %{ $params[1] };
42 }
43 elsif (@params == 2 and ref($params[1]) eq 'ARRAY') {
44 @role_params = @{ $params[1] };
45 }
46 else {
47 @role_params = @params[1..$#params];
48 }
49 my $role = UR::Role::Prototype->define(role_name => $role_name, @role_params);
50 unless ($role) {
51 Carp::croak "error defining role $role_name!";
52 }
53 return sub { $role_name };
54 } else {
55 return;
56 }
57 }
58  
59 foreach my $type ( qw(before after around) ) {
60 my $modifier_class = join('::', 'UR::Role::MethodModifier', ucfirst($type));
61  
62 my $sub = Sub::Name::subname $type => sub {
63 my $subname = shift;
64 my $code = shift;
65  
66 my $package = caller;
67 my $b = $modifier_class->create(
68 role_name => $package,
69 name => $subname,
70 code => $code,
71 );
72 $code;
73 };
74 Sub::Install::install_sub({
75 into => __PACKAGE__,
76 as => $type,
77 code => $sub,
78 });
79 }
80  
81 1;
82  
83 __END__