File Coverage

blib/lib/PRANG/Util.pm
Criterion Covered Total %
statement 12 32 37.5
branch 0 10 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 48 33.3


line stmt bran cond sub pod time code
1              
2             package PRANG::Util;
3             $PRANG::Util::VERSION = '0.20';
4 1     1   7 use strict;
  1         2  
  1         25  
5 1     1   4 use warnings;
  1         2  
  1         29  
6              
7 1         10 use Sub::Exporter -setup =>
8 1     1   5 { exports => [qw(types_of)] };
  1         2  
9              
10 1     1   875 use Set::Object qw(set);
  1         5625  
  1         166  
11              
12             # 12:20 <@mugwump> is there a 'Class::MOP::Class::subclasses' for roles?
13             # 12:20 <@mugwump> I want a list of classes that implement a role
14             # 12:37 <@autarch> mugwump: I'd kind of like to see that in core
15             sub types_of {
16 0     0 0   my @types = @_;
17              
18             # resolve type names to meta-objects;
19 0           for (@types) {
20 0 0         if ( !ref $_ ) {
21 0           $_ = $_->meta;
22             }
23             }
24 0           my $known = set(@types);
25 0           my @roles = grep { $_->isa("Moose::Meta::Role") } @types;
  0            
26              
27 0 0         if (@roles) {
28 0           $known->remove(@roles);
29 0           for my $mc (Class::MOP::get_all_metaclass_instances) {
30 0 0         next if !$mc->isa("Moose::Meta::Class");
31 0 0         next if $known->includes($mc);
32 0 0         if ( grep { $mc->does_role($_->name) } @roles ) {
  0            
33 0           $known->insert($mc);
34             }
35             }
36             }
37 0           for my $class ( $known->members ) {
38 0           my @subclasses = map { $_->meta } $class->subclasses;
  0            
39 0           $known->insert(@subclasses);
40             }
41 0           $known->members;
42             }
43              
44             1;
45              
46             # Copyright (C) 2009, 2010 NZ Registry Services
47             #
48             # This program is free software: you can redistribute it and/or modify
49             # it under the terms of the Artistic License 2.0 or later.
50             #
51             # This program is distributed in the hope that it will be useful,
52             # but WITHOUT ANY WARRANTY; without even the implied warranty of
53             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54             # Artistic License 2.0 for more details.
55             #
56             # You should have received a copy of the Artistic License the file
57             # COPYING.txt. If not, see
58             # <http://www.perlfoundation.org/artistic_license_2_0>