Babble

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Current core plugins are ::CoreSignatures, ::State, ::DefinedOr,
    ::PostfixDeref, ::SubstituteAndReturn (s///r), ::Ellipsis,
    ::PackageBlock, ::PackageVersion, and ::SKT (which is a start on
    rewriting Syntax::Keyword::Try). For an example of an external plugin,
    see Method::Signatures::PP.

    Not for 'normal' use but still interesting, ::Sigify attempts to
    convert simple @_ unrolls into signatures - best used on its own,
    followed by applying App::sigfix if you need the 5.22-5.26
    oldsignatures style.

REPOSITORY

    http://github.com/shadow-dot-cat/Babble/

AUTHOR

    Matt S Trout (mst) <mst@shadowcat.co.uk>

COPYRIGHT AND LICENSE

lib/App/sigfix.pm  view on Meta::CPAN

  my ($text) = @_;
  $text =~ /^(\s+)/ && $text =~ s/^$1//mg;
  $text;
}

sub usage {
  print <<'USAGE';
sigfix [OPTIONS] [FILES]

  sigfix -t signatures perl526file >perl528file
  sigfix -t oldsignatures perl528file >perl526file
  sigfix -t plain perlfile >perl58file

  sigfix -i -t signatures upgradethisfile

  sigfix -t signatures --pmc lib/My/Module.pm >lib/My/Module.pmc
  sigfix -i -t signatures --pmc lib/My/Module.pm

  sigfix -i --pmc eval $(find lib -name '*.pm') # multi-target fat pmc

Options:

  -t, --target     Target: 'signatures', 'oldsignatures', 'plain'
  -i, --inplace    Modify target file(s) in place
  --pmc            Generate .pmc (without -t, triple target pmc)
  -h               This usage message
USAGE

  exit(255);
}

{
  my $cs = Babble::Plugin::CoreSignatures->new;

  my @target_selectors = (
    [ 'signatures', '($] >= 5.020 and $] < 5.022) or $] >= 5.028' ],
    [ 'oldsignatures', '$] >= 5.022 and $] < 5.028' ],
    [ 'plain' ],
  );

  sub process_source {
    my ($source, $opt) = @_;

    if (my $target = $opt->{target}) {

      my $top = Babble::Match->new(
        top_rule => 'Document',

lib/App/sigfix.pm  view on Meta::CPAN


=head1 NAME

App::sigfix - transform files between signature syntax versions

=head1 USAGE

    sigfix [OPTIONS] [FILES]
    
      sigfix -t signatures perl526file >perl528file
      sigfix -t oldsignatures perl528file >perl526file
      sigfix -t plain perlfile >perl58file
    
      sigfix -i -t signatures upgradethisfile
    
      sigfix -t signatures --pmc lib/My/Module.pm >lib/My/Module.pmc
      sigfix -i -t signatures --pmc lib/My/Module.pm
    
      sigfix -i --pmc eval $(find lib -name '*.pm') # multi-target fat pmc
    
    Options:
    
      -t, --target     Target: 'signatures', 'oldsignatures', 'plain'
      -i, --inplace    Modify target file(s) in place
      --pmc            Generate .pmc (without -t, triple target pmc)
      -h               This usage message

=cut

lib/Babble.pm  view on Meta::CPAN

to rewrite for shipping.

Current core plugins are C<::CoreSignatures>, C<::State>, C<::DefinedOr>,
C<::PostfixDeref>, C<::SubstituteAndReturn> (C<s///r>), C<::Ellipsis>,
C<::PackageBlock>, C<::PackageVersion>, and C<::SKT> (which is a start on
rewriting L<Syntax::Keyword::Try>).  For an example of an external plugin,
see L<Method::Signatures::PP>.

Not for 'normal' use but still interesting, C<::Sigify> attempts to convert
simple @_ unrolls into signatures - best used on its own, followed by
applying L<App::sigfix> if you need the 5.22-5.26 oldsignatures style.

=head1 REPOSITORY

L<http://github.com/shadow-dot-cat/Babble/>

=head1 AUTHOR

Matt S Trout (mst) <mst@shadowcat.co.uk>

=head1 COPYRIGHT AND LICENSE

lib/Babble/Plugin/CoreSignatures.pm  view on Meta::CPAN

  my $tf = sub {
    my $s = (my $m = shift)->submatches;
    if ((my $after = $s->{after}->text) =~ /\S/) {
      $s->{after}->replace_text('');
      $s->{before}->replace_text($s->{before}->text.$after);
    }
  };
  $self->_transform_signatures($top, $tf);
}

sub transform_to_oldsignatures {
  my ($self, $top) = @_;
  my $tf = sub {
    my $s = (my $m = shift)->submatches;
    if ((my $before = $s->{before}->text) =~ /\S/) {
      $s->{before}->replace_text('');
      $s->{after}->replace_text($before.$s->{after}->text);
    }
  };
  $self->_transform_signatures($top, $tf);
}

script/sigfix  view on Meta::CPAN


=head1 NAME

sigfix - transform files between signature syntax versions

=head1 USAGE

    sigfix [OPTIONS] [FILES]
    
      sigfix -t signatures perl526file >perl528file
      sigfix -t oldsignatures perl528file >perl526file
      sigfix -t plain perlfile >perl58file
    
      sigfix -i -t signatures upgradethisfile
    
      sigfix -t signatures --pmc lib/My/Module.pm >lib/My/Module.pmc
      sigfix -i -t signatures --pmc lib/My/Module.pm
    
      sigfix -i --pmc eval $(find lib -name '*.pm') # multi-target fat pmc
    
    Options:
    
      -t, --target     Target: 'signatures', 'oldsignatures', 'plain'
      -i, --inplace    Modify target file(s) in place
      --pmc            Generate .pmc (without -t, triple target pmc)
      -h               This usage message

=cut

t/plugin-coresignatures.t  view on Meta::CPAN

my %expect = (
  signatures => <<'END',
  use experimental 'signatures', 'postderef';
  sub left :Attr ($sig, $extra = 2) {
    my $anon_right = sub :Attr ($sig) { }
  }
  sub right :Attr :prototype($) ($sig) {
    my $anon_left = sub :Attr ($sig) { }
  }
END
  oldsignatures => <<'END',
  use experimental 'signatures', 'postderef';
  sub left ($sig, $extra = 2) :Attr {
    my $anon_right = sub ($sig) :Attr { }
  }
  sub right ($sig) :Attr :prototype($) {
    my $anon_left = sub ($sig) :Attr { }
  }
END
  plain => <<'END',
  use experimental qw(postderef);

t/plugin-coresignatures.t  view on Meta::CPAN

  }
  sub right ($) :Attr { my ($sig) = @_;
    my $anon_left = sub :Attr { my ($sig) = @_; }
  }
END
);


my $cs = Babble::Plugin::CoreSignatures->new;

foreach my $type (qw(signatures oldsignatures plain)) {
  my $top = Babble::Match->new(top_rule => 'Document', text => $code);
  $cs->${\"transform_to_${type}"}($top);
  is($top->text, $expect{$type}, "Rendered ${type} correctly");
}

my @cand = (
  [ 'sub foo :prototype($) ($sig) { }',
    'sub foo ($) { my ($sig) = @_; }', ],
  [ 'sub foo :Foo :prototype($) ($sig) { }',
    'sub foo ($) :Foo { my ($sig) = @_; }', ],



( run in 2.641 seconds using v1.01-cache-2.11-cpan-71847e10f99 )