| 1 | package Forest::Tree::Reader::SimpleTextFile; | ||
| 2 | 10 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | 10 | our $VERSION = '0.10'; | |
| 5 | 10 | our $AUTHORITY = 'cpan:STEVAN'; | |
| 6 | |||
| 7 | 10 | ▶ | use Forest::Tree::Builder::SimpleTextFile; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 10 | with qw(Forest::Tree::Reader Forest::Tree::Constructor); # see new_subtree_callback below | |
| 10 | |||
| 11 | # FIXME these are for compat... remove them? | ||
| 12 | |||
| 13 | 10 | has 'tab_width' => ( | |
| 14 | is => 'rw', | ||
| 15 | isa => 'Int', | ||
| 16 | default => 4 | ||
| 17 | ); | ||
| 18 | |||
| 19 | 10 | has 'parser' => ( | |
| 20 | is => 'rw', | ||
| 21 | isa => 'CodeRef', | ||
| 22 | lazy => 1, | ||
| 23 | builder => 'build_parser', | ||
| 24 | ); | ||
| 25 | |||
| 26 | 7 | ▶ | sub build_parser { |
|
Subroutine
build_parser: called CC=1 SCAR=0.0
Pod
documented
| |||
| 27 | 71 | ▶ | return sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 28 | 71 | my ($self, $line) = @_; | |
| 29 | 71 | my ($indent, $node) = ($line =~ /^(\s*)(.*)$/); | |
| 30 | 71 | my $depth = ((length $indent) / $self->tab_width); | |
| 31 | 71 | return ($depth, $node); | |
| 32 | } | ||
| 33 | 7 | } | |
| 34 | |||
| 35 | 0 | ▶ | sub parse_line { $_[0]->parser->(@_) } |
|
Subroutine
parse_line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 36 | |||
| 37 | # compat endscreate_new_subtree(@_);}, | ||
| 38 | |||
| 39 | 8 | ▶ | sub read { |
|
Subroutine
read: called CC=2 SCAR=6.9
Pod
documented
| |||
| 40 | 8 | my ($self, $fh) = @_; | |
| 41 | |||
| 42 | my $builder = Forest::Tree::Builder::SimpleTextFile->new( | ||
| 43 | tree_class => ref( $self->tree ), | ||
| 44 | tab_width => $self->tab_width, | ||
| 45 | parser => $self->parser, | ||
| 46 | fh => $fh, | ||
| 47 | |||
| 48 | # since it's possible to subclass reader and implement this method, we | ||
| 49 | # include Forest::Tree::Constructor into this class as well, and make | ||
| 50 | # the builder use that definition (which under normal circumstances | ||
| 51 | # will be the same, Forest::Tree::Constructor::create_new_subtree) | ||
| 52 | 76 | ▶ | new_subtree_callback => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 53 | 76 | my ( $builder, @args ) = @_; | |
| 54 | 76 | $self->create_new_subtree(@args); | |
| 55 | }, | ||
| 56 | 8 | ); | |
| 57 | |||
| 58 | 8 | $self->tree->add_child($_) for @{ $builder->subtrees }; | |
| 59 | } | ||
| 60 | |||
| 61 | 10 | __PACKAGE__->meta->make_immutable; | |
| 62 | |||
| 63 | 10 | ▶ | no Moose; 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 64 | |||
| 65 | __END__ | ||