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; |