X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=script%2Frclass_back_to_moose.pl;h=c34392e1317f9c1376edcf8d1163a7bd29e3e225;hb=d219104c2b30374f08415c86a8cdcb1bc9dda9a1;hp=0b5321fe559c834ea6cced312c355195ea53e3c4;hpb=b134d5b65b4e26215f871b3c94ad8397af3d00a3;p=catagits%2FReaction.git diff --git a/script/rclass_back_to_moose.pl b/script/rclass_back_to_moose.pl index 0b5321f..c34392e 100644 --- a/script/rclass_back_to_moose.pl +++ b/script/rclass_back_to_moose.pl @@ -18,9 +18,9 @@ sub with_file (&) { 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; } @@ -29,7 +29,7 @@ sub parse_header { 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; @@ -48,18 +48,19 @@ sub sq { # short for 'strip quotes' } sub filtered_body { + my $is_widget = m/WidgetClass/; 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 unless $is_widget; + 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;