-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proof-of-concept for feature-tracking and perl sub signatures (see #273)
- Loading branch information
1 parent
3cd40bb
commit 4fedb89
Showing
6 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package PPI::Token::Signature; | ||
|
||
=pod | ||
=head1 NAME | ||
PPI::Token::Signature - A subroutine signature descriptor | ||
=head1 INHERITANCE | ||
PPI::Token::Signature | ||
isa PPI::Token::Prototype | ||
isa PPI::Token | ||
isa PPI::Element | ||
=head1 SYNOPSIS | ||
TODO: document | ||
=head1 DESCRIPTION | ||
TODO: document | ||
=cut | ||
|
||
use strict; | ||
use PPI::Token::Prototype (); | ||
|
||
our $VERSION = '1.276'; | ||
|
||
our @ISA = "PPI::Token::Prototype"; | ||
|
||
1; | ||
|
||
=pod | ||
=head1 SUPPORT | ||
See the L<support section|PPI/SUPPORT> in the main module. | ||
=head1 AUTHOR | ||
Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||
=head1 COPYRIGHT | ||
Copyright 2001 - 2011 Adam Kennedy. | ||
This program is free software; you can redistribute | ||
it and/or modify it under the same terms as Perl itself. | ||
The full text of the license can be found in the | ||
LICENSE file included with this module. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/perl | ||
|
||
use lib 't/lib'; | ||
use PPI::Test::pragmas; | ||
use Test::More tests => 1 + ( $ENV{AUTHOR_TESTING} ? 1 : 0 ); | ||
|
||
use B 'perlstring'; | ||
|
||
use PPI (); | ||
|
||
#use DB::Skip subs => [ | ||
# qw( PPI::Document::new PPI::Lexer::lex_source PPI::Lexer::new | ||
# PPI::Lexer::_clear PPI::Lexer::(eval) PPI::Lexer::X_TOKENIZER | ||
# PPI::Tokenizer::new PPI::Lexer::lex_tokenizer PPI::Node::new ), | ||
# qr/^PPI::Tokenizer::__ANON__.*237.*$/ | ||
#]; | ||
|
||
sub test_document; | ||
|
||
FEATURE_TRACKING: { | ||
test_document | ||
<<'END_PERL', | ||
sub meep(&$) {} | ||
use 5.035; | ||
sub marp($left, $right) {} | ||
END_PERL | ||
[ | ||
'PPI::Statement::Sub' => 'sub meep(&$) {}', | ||
'PPI::Token::Word' => 'sub', | ||
'PPI::Token::Word' => 'meep', | ||
'PPI::Token::Prototype' => '(&$)', | ||
'PPI::Structure::Block' => '{}', | ||
'PPI::Token::Structure' => '{', | ||
'PPI::Token::Structure' => '}', | ||
'PPI::Statement::Include' => 'use 5.035;', | ||
'PPI::Token::Word' => 'use', | ||
'PPI::Token::Number::Float' => '5.035', | ||
'PPI::Token::Structure' => ';', | ||
'PPI::Statement::Sub' => 'sub marp($left, $right) {}', | ||
'PPI::Token::Word' => 'sub', | ||
'PPI::Token::Word' => 'marp', | ||
'PPI::Token::Signature' => '($left, $right)', # !!!!!!!!!!!!!!!!!!!! | ||
'PPI::Structure::Block' => '{}', | ||
'PPI::Token::Structure' => '{', | ||
'PPI::Token::Structure' => '}', | ||
]; | ||
} | ||
|
||
### TODO from ppi_token_unknown.t , deduplicate | ||
|
||
sub one_line_explain { | ||
my ($data) = @_; | ||
my @explain = explain $data; | ||
s/\n//g for @explain; | ||
return join "", @explain; | ||
} | ||
|
||
sub main_level_line { | ||
return "" if not $TODO; | ||
my @outer_final; | ||
my $level = 0; | ||
while ( my @outer = caller( $level++ ) ) { | ||
@outer_final = @outer; | ||
} | ||
return "l $outer_final[2] - "; | ||
} | ||
|
||
sub test_document { | ||
local $Test::Builder::Level = $Test::Builder::Level + 1; | ||
my ( $code, $expected, $msg ) = @_; | ||
$msg = perlstring $code if !defined $msg; | ||
|
||
my $d = PPI::Document->new( \$code ); | ||
my $tokens = $d->find( sub { $_[1]->significant } ); | ||
$tokens = [ map { ref($_), $_->content } @$tokens ]; | ||
|
||
my $ok = is_deeply( $tokens, $expected, main_level_line . $msg ); | ||
if ( !$ok ) { | ||
diag ">>> $code -- $msg\n"; | ||
diag one_line_explain $tokens; | ||
diag one_line_explain $expected; | ||
} | ||
|
||
return; | ||
} |