----- Mail original -----
> Hi all,
> 
> I've written a patch which adds support for the aforementioned modules
> in Padre::Document::Perl::Outline,
> Padre::Document::Perl::FunctionList, and Padre::Document::Perl. So far
> this patch works with everything that I've thrown at it. I'm now in
> the process of writing some tests. I could use some help with this
> part.
> 
> Could someone create a Trac account for me so that I can submit a
> ticket? Actually, do I need to submit a ticket or is discussing it
> here enough to get the right people looking at the patch?

Sorry. I should have attached the patch to my prior e-mail.

It's still in progress, but attached is what I have so far.

I'm also attaching two scripts I created during development:

list_ms_meths.pl - initial approach; unfeasible due to extra requirements, but 
super helpful to verify that methods are detected properly
list_ms_meths_sans_b.pl - current approach; works like existing code which uses 
PPI

-- 
Darian Anthony Patrick   XMPP/SMTP: <d...@darianpatrick.com>
===========================================================
     88FC 044D 5144 BD3A DAF8 FD9F 8C9E DF14 9AD3 4117
===========================================================

Attachment: list_ms_meths.pl
Description: Perl program

Attachment: list_ms_meths_sans_b.pl
Description: Perl program

Index: lib/Padre/Document/Perl/Outline.pm
===================================================================
--- lib/Padre/Document/Perl/Outline.pm	(revision 12320)
+++ lib/Padre/Document/Perl/Outline.pm	(working copy)
@@ -38,6 +38,9 @@
 		}
 	)->in($ppi);
 
+	# Define a flag indicating that further Method::Signature/Moose check should run
+	my $check_alternate_sub_decls = 0;
+
 	# Build the outline structure from the search results
 	my @outline       = ();
 	my $cur_pkg       = {};
@@ -60,6 +63,13 @@
 				push @{ $cur_pkg->{pragmata} }, { name => $thing->pragma, line => $thing->location->[0] };
 			} elsif ( $thing->module ) {
 				push @{ $cur_pkg->{modules} }, { name => $thing->module, line => $thing->location->[0] };
+				unless ( $check_alternate_sub_decls ) {
+					$check_alternate_sub_decls = 1
+						if grep {$thing->module eq $_}
+							('Method::Signatures',
+							 'MooseX::Declare',
+							 'MooseX::Method::Signatures');
+				}
 			}
 		} elsif ( ref $thing eq 'PPI::Statement::Sub' ) {
 			push @{ $cur_pkg->{methods} }, { name => $thing->name, line => $thing->location->[0] };
@@ -84,9 +94,30 @@
 		}
 	}
 
+	if ( $check_alternate_sub_decls ) {
+		$ppi->find(sub {
+			my $sib_content;
+			my $matched = (
+				$_[1]->isa('PPI::Token::Word')
+				&& grep($_[1]->content() eq $_ , qw/func method/)
+				&& $_[1]->next_sibling()->isa('PPI::Token::Whitespace')
+				&& ($sib_content = $_[1]->next_sibling()->next_sibling->content())
+			);
+			return 0 unless $matched;
+
+			$sib_content =~ m/^\b(\w+)\b/;
+			return 0 unless defined $1;
+
+			push @{ $cur_pkg->{methods} }, { name => $1, line => $_[1]->line_number };
+
+			return 1;
+		});
+	}
+
 	if ( not $cur_pkg->{name} ) {
 		$cur_pkg->{name} = 'main';
 	}
+
 	push @outline, $cur_pkg;
 
 	return \...@outline;
Index: lib/Padre/Document/Perl/FunctionList.pm
===================================================================
--- lib/Padre/Document/Perl/FunctionList.pm	(revision 12320)
+++ lib/Padre/Document/Perl/FunctionList.pm	(working copy)
@@ -21,7 +21,7 @@
 		|
 		$n$n=\w+.*?$n$n=cut\b(?=.*?$n$n)
 		|
-		(?:^|$n)\s*sub\s+(\w+(?:::\w+)*)
+		(?:^|$n)\s*(?:sub|func|method)\s+(\w+(?:::\w+)*)
 		)
 	/sx;
 
Index: lib/Padre/Document/Perl.pm
===================================================================
--- lib/Padre/Document/Perl.pm	(revision 12320)
+++ lib/Padre/Document/Perl.pm	(working copy)
@@ -740,7 +740,11 @@
 						my @subs = $lines =~ /\bmethod\s+(\w+)/g;
 					}
 
+					if ( $lines =~ /use (?:MooseX::)?Method::Signatures;/ ) {
+						my @subs = $lines =~ /\b(?:method|func)\s+(\w+)/g;
+					}
 
+
 					#use Data::Dumper;
 					#print Dumper \...@subs;
 					$self->{_methods_}{$_} = $f for @subs;
_______________________________________________
Padre-dev mailing list
Padre-dev@perlide.org
http://mail.perlide.org/mailman/listinfo/padre-dev

Reply via email to