From: Shawn M Moore Date: Tue, 28 Apr 2009 08:34:09 +0000 (-0400) Subject: Add a Perl::Critic::Util::Moose which has a meta_type for classifying X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FPerl-Critic-Dynamic-Moose.git;a=commitdiff_plain;h=8a69e820c5db791149ecb823a0a20e05757c7f97 Add a Perl::Critic::Util::Moose which has a meta_type for classifying metaclasses --- diff --git a/lib/Perl/Critic/Util/Moose.pm b/lib/Perl/Critic/Util/Moose.pm new file mode 100644 index 0000000..f65520b --- /dev/null +++ b/lib/Perl/Critic/Util/Moose.pm @@ -0,0 +1,32 @@ +package Perl::Critic::Util::Moose; +use strict; +use warnings; +use base 'Exporter'; + +our @EXPORTS_OK = 'meta_type'; + +my @types = ( + [ 'Moose::Meta::Role' => 'role' ], + [ 'Moose::Meta::TypeCoercion' => 'type coercion' ], + [ 'Moose::Meta::TypeConstraint' => 'type constraint' ], + + [ 'Class::MOP::Method' => 'method' ], + [ 'Class::MOP::Attribute' => 'attribute' ], + [ 'Class::MOP::Class' => 'class' ], + [ 'Class::MOP::Module' => 'module' ], + [ 'Class::MOP::Package' => 'package' ], +); + +sub meta_type { + my $meta = shift; + + for (@types) { + my ($class, $name) = @$_; + return $name if $meta->isa($class); + } + + return undef; +} + +1; +