Add a Perl::Critic::Util::Moose which has a meta_type for classifying
Shawn M Moore [Tue, 28 Apr 2009 08:34:09 +0000 (04:34 -0400)]
metaclasses

lib/Perl/Critic/Util/Moose.pm [new file with mode: 0644]

diff --git a/lib/Perl/Critic/Util/Moose.pm b/lib/Perl/Critic/Util/Moose.pm
new file mode 100644 (file)
index 0000000..f65520b
--- /dev/null
@@ -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;
+