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