/[Frey]/trunk/lib/Frey/PPI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Frey/PPI.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 331 - (show annotations)
Sat Nov 8 16:12:39 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 839 byte(s)
implement PPI parser to get default attribute_order
1 package Frey::PPI;
2 use Moose;
3
4 extends 'Frey::ClassLoader';
5
6 use PPI;
7 use Data::Dump qw/dump/;
8
9 has 'class' => (
10 is => 'rw',
11 isa => 'Str',
12 required => 1,
13 documentation => 'Name of class to parse',
14 );
15
16 sub attribute_order {
17 my ( $self ) = @_;
18
19 my $doc = PPI::Document->new( $self->class_path( $self->class ) ) || die $!;
20
21 $doc->prune('PPI::Token::Whitespace');
22
23 my @attribute_order;
24
25 $doc->find(sub {
26 my ($doc,$el) = @_;
27 if ( $el->isa('PPI::Statement') && $el->{children}->[0]->{content} eq 'has' ) {
28 warn "## has ",$el->{children}->[1]->string if $self->debug;
29 push @attribute_order, $el->{children}->[1]->string;
30 }
31 return 1;
32 });
33
34 warn "# ", $self->class, " attribute_order ", dump( @attribute_order ) if $self->debug;
35
36 return @attribute_order;
37 }
38
39 sub data {
40 my $self = shift;
41 [ $self->attribute_order ];
42 }
43
44 1;

  ViewVC Help
Powered by ViewVC 1.1.26