/[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 362 - (show annotations)
Sun Nov 16 17:39:39 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1344 byte(s)
collect include from PPI::Statement::Include
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 my $ppi_doc;
17
18 sub doc {
19 my ( $self ) = @_;
20
21 if ( ! $ppi_doc ) {
22 warn "# parse ", $self->class;
23 my $doc = PPI::Document->new( $self->class_path( $self->class ) ) || die $!;
24 $doc->prune('PPI::Token::Whitespace');
25 $ppi_doc = $doc;
26 }
27 return $ppi_doc;
28 }
29
30 sub attribute_order {
31 my ( $self ) = @_;
32
33 my $doc = $self->doc;
34
35 my @attribute_order;
36
37 $doc->find(sub {
38 my ($doc,$el) = @_;
39 if ( $el->isa('PPI::Statement') && $el->{children}->[0]->{content} eq 'has' ) {
40 warn "## has ",$el->{children}->[1]->string if $self->debug;
41 push @attribute_order, $el->{children}->[1]->string;
42 }
43 return 1;
44 });
45
46 warn "# ", $self->class, " attribute_order ", dump( @attribute_order ) if $self->debug;
47
48 return @attribute_order;
49 }
50
51 sub data {
52 my $self = shift;
53 my $doc = $self->doc;
54 my $include;
55 $doc->find( sub {
56 my ($doc,$el) = @_;
57 if ( $el->isa('PPI::Statement::Include') ) {
58 warn dump( $el->module, $el->type, $el->pragma );
59 push @{ $include->{ $el->type } }, $el->module
60 }
61 return 1;
62 });
63 warn "# ", $self->class, " ", dump( $include ) if $self->debug;
64
65 return {
66 include => $include,
67 doc => $doc,
68 };
69 }
70
71 1;

  ViewVC Help
Powered by ViewVC 1.1.26