File Coverage

blib/lib/MOP/Util.pm
Criterion Covered Total %
statement 27 34 79.4
branch 2 8 25.0
condition 3 9 33.3
subroutine 8 9 88.8
pod 4 4 100.0
total 44 64 68.7


line stmt bran cond sub pod time code
1             package MOP::Util;
2             # ABSTRACT: For MOP External Use Only
3              
4 7     7   34 use strict;
  7         11  
  7         155  
5 7     7   27 use warnings;
  7         9  
  7         133  
6              
7 7     7   25 use MOP::Role;
  7         12  
  7         126  
8 7     7   22 use MOP::Class;
  7         16  
  7         105  
9 7     7   30 use MOP::Internal::Util ();
  7         11  
  7         1797  
10              
11             our $VERSION = '0.11';
12             our $AUTHORITY = 'cpan:STEVAN';
13              
14             sub get_meta {
15 5     5 1 1011 my ($package) = @_;
16              
17 5         24 my $meta = MOP::Role->new( $package );
18 5         101 my $isa = MOP::Internal::Util::GET_GLOB_SLOT( $meta->stash, 'ISA', 'ARRAY' );
19              
20             # without inheritance, we assume it is a role ...
21 5 50 33     27 return $meta
      66        
22             if not defined $isa
23             || (ref $isa eq 'ARRAY' && scalar @$isa == 0);
24              
25             # with inheritance, we know it is a class ....
26 1         7 return MOP::Class->new( $package );
27             }
28              
29             sub compose_roles {
30 5     5 1 26 my ($meta) = @_;
31              
32 5         11 my @roles = $meta->roles;
33 5 50       22 MOP::Internal::Util::APPLY_ROLES( $meta, \@roles ) if @roles;
34 5         46 return;
35             }
36              
37             sub inherit_slots {
38 0     0 1 0 my ($meta) = @_;
39              
40             # roles don't inherit, so do nothing ...
41 0 0       0 return unless $meta->isa('MOP::Class');
42              
43             # otherwise, inherit only the slots from
44             # the direct superclasses, this assumes that
45             # these superclasses have already done
46             # INHERIT_SLOTS themselves.
47 0         0 foreach my $super ( map { MOP::Role->new( name => $_ ) } $meta->superclasses ) {
  0         0  
48             # remember to use all_slots so that it
49             # will gives us *all* the slots, including
50             # those that are themselves inherited ...
51 0         0 foreach my $slot ( $super->all_slots ) {
52             # we always just alias this anyway ...
53 0 0 0     0 $meta->alias_slot( $slot->name, $slot->initializer )
54             unless $meta->has_slot( $slot->name )
55             || $meta->has_slot_alias( $slot->name );
56             }
57             }
58              
59             # nothing to return ...
60 0         0 return;
61             }
62              
63             sub defer_until_UNITCHECK {
64 5     5 1 4229 my ($cb) = @_;
65              
66 5         17 MOP::Internal::Util::ADD_UNITCHECK_HOOK( $cb );
67 5         1973 return;
68             }
69              
70             1;
71              
72             __END__