| 1 | |||||||||||
| 2 | package PRANG::Util; | ||||||||||
| 3 | 11 | $PRANG::Util::VERSION = '0.21'; | |||||||||
| 4 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 11 | ▶ | use Sub::Exporter -setup => | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 11 | { exports => [qw(types_of)] }; | |||||||||
| 9 | |||||||||||
| 10 | 11 | ▶ | use Set::Object qw(set); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 13 | ▶ | sub types_of { | ||||||||
|
Subroutine
types_of: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||
| 16 | 13 | my @types = @_; | |||||||||
| 17 | |||||||||||
| 18 | # resolve type names to meta-objects; | ||||||||||
| 19 | 13 | for (@types) { | |||||||||
| 20 | 13 | ▶ | if ( !ref $_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 6 | $_ = $_->meta; | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | 13 | my $known = set(@types); | |||||||||
| 25 | 13 | my @roles = grep { $_->isa("Moose::Meta::Role") } @types; | |||||||||
| 26 | |||||||||||
| 27 | 13 | ▶ | if (@roles) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 13 | $known->remove(@roles); | |||||||||
| 29 | 13 | for my $mc (Class::MOP::get_all_metaclass_instances) { | |||||||||
| 30 | 1292 | ▶ | next if !$mc->isa("Moose::Meta::Class"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 286 | ▶ | next if $known->includes($mc); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 286 | ▶ | if ( grep { $mc->does_role($_->name) } @roles ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 27 | $known->insert($mc); | |||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | 13 | for my $class ( $known->members ) { | |||||||||
| 38 | 0 | my @subclasses = map { $_->meta } $class->subclasses; | |||||||||
| 39 | 27 | $known->insert(@subclasses); | |||||||||
| 40 | } | ||||||||||
| 41 | 13 | $known->members; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 11 | 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> | ||||||||||