| 1 | package Text::APL::Core; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use base 'Text::APL::Base'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Text::APL::Compiler; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use Text::APL::Context; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use Text::APL::Parser; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use Text::APL::Reader; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 2 | ▶ | use Text::APL::Translator; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | ▶ | use Text::APL::Writer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | sub _BUILD { | ||||||||||||||||||||
| 18 | 20 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_BUILD: called CC=6 SCAR=22.9
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 20 | ▶ | $self->{parser} ||= Text::APL::Parser->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"parser"} ||= "Text::APL::Parser"->new
MC/DC0%0/2
$self->{"parser"} ||= "Text::APL::Parser"->new
$self->{"parser"}
"Text::APL::Parser"->new
Truth table33%1/3
A ||= B
A= $self->{"parser"}B= "Text::APL::Parser"->new
| |||||||||||||||||||||
| 21 | 20 | ▶ | $self->{translator} ||= Text::APL::Translator->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"translator"} ||= "Text::APL::Translator"->new
MC/DC0%0/2
$self->{"translator"} ||= "Text::APL::Translator"->new
$self->{"translator"}
"Text::APL::Translator"->new
Truth table33%1/3
A ||= B
A= $self->{"translator"}B= "Text::APL::Translator"->new
| |||||||||||||||||||||
| 22 | 20 | ▶ | $self->{compiler} ||= Text::APL::Compiler->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"compiler"} ||= "Text::APL::Compiler"->new
MC/DC0%0/2
$self->{"compiler"} ||= "Text::APL::Compiler"->new
$self->{"compiler"}
"Text::APL::Compiler"->new
Truth table33%1/3
A ||= B
A= $self->{"compiler"}B= "Text::APL::Compiler"->new
| |||||||||||||||||||||
| 23 | 20 | ▶ | $self->{reader} ||= Text::APL::Reader->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"reader"} ||= "Text::APL::Reader"->new
MC/DC0%0/2
$self->{"reader"} ||= "Text::APL::Reader"->new
$self->{"reader"}
"Text::APL::Reader"->new
Truth table33%1/3
A ||= B
A= $self->{"reader"}B= "Text::APL::Reader"->new
| |||||||||||||||||||||
| 24 | 20 | ▶ | $self->{writer} ||= Text::APL::Writer->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"writer"} ||= "Text::APL::Writer"->new
MC/DC0%0/2
$self->{"writer"} ||= "Text::APL::Writer"->new
$self->{"writer"}
"Text::APL::Writer"->new
Truth table33%1/3
A ||= B
A= $self->{"writer"}B= "Text::APL::Writer"->new
| |||||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub render { | ||||||||||||||||||||
| 28 | 22 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 29 | 22 | my (%params) = @_; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 22 | my $return = ''; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | my $writer = | ||||||||||||||||||||
| 34 | $self->{writer} | ||||||||||||||||||||
| 35 | 22 | ▶ | ->build(exists $params{output} ? $params{output} : \$return); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | my $context = Text::APL::Context->new( | ||||||||||||||||||||
| 38 | helpers => $params{helpers}, | ||||||||||||||||||||
| 39 | vars => $params{vars}, | ||||||||||||||||||||
| 40 | name => $params{name} | ||||||||||||||||||||
| 41 | 22 | ); | |||||||||||||||||||
| 42 | 22 | ▶ | $context->add_helper(__print => sub { $writer->(@_) }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | $context->add_helper( | ||||||||||||||||||||
| 44 | __print_escaped => sub { | ||||||||||||||||||||
| 45 | 18 | ▶ | my ($input) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 18 | ▶ | return $writer->('') unless defined $input; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 18 | for ($input) { s/&/&/g; s/</</g; s/>/>/g; s/"/"/g; s/'/'/g } | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 18 | $writer->($input); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 22 | ); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | $self->_process( | ||||||||||||||||||||
| 56 | $params{input}, | ||||||||||||||||||||
| 57 | $context, | ||||||||||||||||||||
| 58 | sub { | ||||||||||||||||||||
| 59 | 21 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | 21 | my ($sub_ref) = @_; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 21 | $sub_ref->($context); | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 21 | $writer->(); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | 22 | ); | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 21 | ▶ | return exists $params{output} ? $self : $return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub _process { | ||||||||||||||||||||
| 72 | 20 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_process: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 73 | 20 | my ($input, $context, $cb) = @_; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | $self->_parse( | ||||||||||||||||||||
| 76 | $input => sub { | ||||||||||||||||||||
| 77 | 20 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 78 | 20 | my ($tape) = @_; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 20 | my $code = $self->_translate($tape); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 20 | my $sub_ref = $self->_compile($code, $context); | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 19 | $cb->($self, $sub_ref); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | 20 | ); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | sub _parse { | ||||||||||||||||||||
| 90 | 20 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_parse: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | 20 | my ($input, $cb) = @_; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 20 | my $parser = $self->{parser}; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 20 | my $reader = $self->{reader}->build($input); | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 20 | my $tape = []; | |||||||||||||||||||
| 98 | my $reader_cb = sub { | ||||||||||||||||||||
| 99 | 40 | ▶ | my ($chunk) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 40 | ▶ | if (!defined $chunk) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 20 | my $leftover = $parser->parse(); | |||||||||||||||||||
| 103 | 20 | ▶ | push @$tape, @$leftover if $leftover; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 20 | $cb->($self, $tape); | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||
| 108 | 20 | my $subtape = $parser->parse($chunk); | |||||||||||||||||||
| 109 | 20 | ▶ | push @$tape, @$subtape if @$subtape; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | 20 | }; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 20 | $reader->($reader_cb, $input); | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | sub _translate { | ||||||||||||||||||||
| 117 | 20 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_translate: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 118 | 20 | my ($tape) = @_; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 20 | return $self->{translator}->translate($tape); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | sub _compile { | ||||||||||||||||||||
| 124 | 21 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
_compile: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 125 | 21 | my ($code, $context) = @_; | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 21 | return $self->{compiler}->compile($code, $context); | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 2 | 1; | |||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||