sub with_class_or_role_block (&) {
my ($code) = @_;
- $_ =~ s{^(?:class|role)\s*(.*?)which\s*{(.*?)^};}
+ $_ =~ s{^(class|role)\s*(.*?)which\s*{(.*?)^};}
{
- local *_ = { header => $1, body => $2 };
+ local *_ = { type => $1, header => $2, body => $3 };
$code->();
}sme;
}
my $h = $_{header};
$h =~ s/^\s*\S+\s+// || die;
my @base;
- while ($h =~ /is\s*(\S+?),?/g) {
+ while ($h =~ /is\s*([^ ,]+),?/g) {
push(@base, $1);
}
return @base;
sub filtered_body {
local $_ = $_{body};
s/^ //g;
- s/implements *(\S+).*?{/"sub ${\sq $1} {"/ge;
- s/^does/with/g;
- s/^overrides/override/g;
+ s/^\s*implements *(\S+).*?{/"sub ${\sq $1} {"/ge;
+ s/^\s*does/with/g;
+ s/^\s*overrides/override/g;
$_;
}
sub top { "use namespace::clean -except => [ qw(meta) ];\n" }
-sub tail { "__PACKAGE__->meta->make_immutable;\n"; }
+sub tail { $_{type} eq 'class' ? "__PACKAGE__->meta->make_immutable;\n" : ""; }
-for ("lib/Reaction/InterfaceModel/Object.pm", "lib/Reaction/InterfaceModel/Action/DBIC/Result.pm") {
+for (@ARGV) {
with_file {
with_class_or_role_block {
return top.build_extends.filtered_body.tail;