diff --git a/lib/Babble/Plugin/Ellipsis.pm b/lib/Babble/Plugin/Ellipsis.pm new file mode 100644 index 0000000..00faf90 --- /dev/null +++ b/lib/Babble/Plugin/Ellipsis.pm @@ -0,0 +1,36 @@ +package Babble::Plugin::Ellipsis; + +use Moo; + +sub transform_to_plain { + my ($self, $top) = @_; + $top->each_match_within(Statement => [ + '\.\.\.' + ] => sub { + my ($m) = @_; + $m->replace_text(q|die 'Unimplemented'|); + }); +} + +1; +__END__ + +=head1 NAME + +Babble::Plugin::Ellipsis - Plugin for ellipsis / yada yada yada statement + +=head1 SYNOPSIS + +Converts usage of the ellipsis syntax from + + ... + +to + + die 'Unimplemented' + +=head1 SEE ALSO + +L<... syntax|Syntax::Construct/...> + +=cut diff --git a/t/plugin-ellipsis.t b/t/plugin-ellipsis.t new file mode 100644 index 0000000..2710a16 --- /dev/null +++ b/t/plugin-ellipsis.t @@ -0,0 +1,24 @@ +use strictures 2; +use Test::More; +use Babble::Plugin::Ellipsis; +use Babble::Match; + +my $el = Babble::Plugin::Ellipsis->new; + +my @cand = ( + # just ellipsis + [ 'sub foo {...}', + q|sub foo {die 'Unimplemented'}|, ], + # partial ellipsis + [ 'sub foo { f; ...; g; }', + q|sub foo { f; die 'Unimplemented'; g; }|, ], +); + +foreach my $cand (@cand) { + my ($from, $to) = @$cand; + my $top = Babble::Match->new(top_rule => 'Document', text => $from); + $el->transform_to_plain($top); + is($top->text, $to, "${from}"); +} + +done_testing;