| 1 | package PerlActor::Script; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use base 'PerlActor::Object'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use fields qw( lines name currentLine currentLineNumber ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Error qw( :try ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use PerlActor::CommandFactory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use PerlActor::LineTokenizer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use PerlActor::Exception::AssertionFailure; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use PerlActor::Exception::CommandFailed; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use PerlActor::Exception::CommandAborted; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | #=============================================================================================== | ||||||||||
| 14 | # Public Methods | ||||||||||
| 15 | #=============================================================================================== | ||||||||||
| 16 | |||||||||||
| 17 | sub new | ||||||||||
| 18 | 7 | ▶ | { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 19 | 7 | my $proto = shift; | |||||||||
| 20 | 7 | my $self = $proto->SUPER::new(@_); | |||||||||
| 21 | 7 | $self->{name} = shift; | |||||||||
| 22 | 7 | $self->{lines} = []; | |||||||||
| 23 | 7 | $self->setContext( {} ); | |||||||||
| 24 | 7 | return $self; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | sub setLines | ||||||||||
| 28 | 6 | ▶ | { | ||||||||
|
Subroutine
setLines: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 29 | 6 | my $self = shift; | |||||||||
| 30 | 6 | my @lines = @_; | |||||||||
| 31 | 6 | $self->{lines} = \@lines; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub getName | ||||||||||
| 35 | 1 | ▶ | { | ||||||||
|
Subroutine
getName: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | 1 | my $self = shift; | |||||||||
| 37 | 1 | return $self->{name}; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub execute | ||||||||||
| 41 | 6 | ▶ | { | ||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 6 | my $self = shift; | |||||||||
| 43 | |||||||||||
| 44 | 6 | my $listener = $self->getListener(); | |||||||||
| 45 | 6 | $listener->scriptStarted($self); | |||||||||
| 46 | |||||||||||
| 47 | try | ||||||||||
| 48 | 6 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 49 | 6 | $self->_processLines(); | |||||||||
| 50 | 3 | $listener->scriptPassed($self); | |||||||||
| 51 | 3 | $listener->scriptEnded($self); | |||||||||
| 52 | } | ||||||||||
| 53 | catch PerlActor::Exception::CommandFailed with | ||||||||||
| 54 | 1 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 1 | my $exception = shift; | |||||||||
| 56 | 1 | $listener->scriptFailed($self, $exception); | |||||||||
| 57 | 1 | $listener->scriptEnded($self); | |||||||||
| 58 | } | ||||||||||
| 59 | catch PerlActor::Exception::CommandAborted with | ||||||||||
| 60 | 2 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 2 | my $exception = shift; | |||||||||
| 62 | 2 | $listener->scriptAborted($self, $exception); | |||||||||
| 63 | 6 | }; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub executeCommand | ||||||||||
| 67 | 9 | ▶ | { | ||||||||
|
Subroutine
executeCommand: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 68 | 9 | my $self = shift; | |||||||||
| 69 | 9 | my $command = shift; | |||||||||
| 70 | |||||||||||
| 71 | 9 | my $listener = $self->getListener(); | |||||||||
| 72 | 9 | $command->setContext($self->getContext()); | |||||||||
| 73 | 9 | $command->setListener($listener); | |||||||||
| 74 | 9 | $listener->commandStarted($self, $command); | |||||||||
| 75 | 9 | my $success; | |||||||||
| 76 | try | ||||||||||
| 77 | 9 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 78 | 9 | $command->execute(); | |||||||||
| 79 | 6 | $listener->commandPassed($self, $command); | |||||||||
| 80 | 6 | $listener->commandEnded($self, $command); | |||||||||
| 81 | } | ||||||||||
| 82 | catch PerlActor::Exception::AssertionFailure with | ||||||||||
| 83 | 1 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 84 | 1 | my $exception = shift; | |||||||||
| 85 | 1 | $listener->commandFailed($self, $command, $exception); | |||||||||
| 86 | 1 | $listener->commandEnded($self, $command); | |||||||||
| 87 | 1 | throw PerlActor::Exception::CommandFailed("$exception\n"); | |||||||||
| 88 | } | ||||||||||
| 89 | otherwise | ||||||||||
| 90 | 2 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 2 | my $exception = shift; | |||||||||
| 92 | 2 | $listener->commandAborted($self, $command, $exception); | |||||||||
| 93 | 2 | throw PerlActor::Exception::CommandAborted("$exception\n"); | |||||||||
| 94 | 9 | }; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | sub parse | ||||||||||
| 98 | 1 | ▶ | { | ||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 99 | 1 | my $self = shift; | |||||||||
| 100 | 1 | return $self->_parseLines(@{$self->{lines}}); | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | sub getTraceInfo | ||||||||||
| 104 | 0 | ▶ | { | ||||||||
|
Subroutine
getTraceInfo: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | 0 | my $self = shift; | |||||||||
| 106 | 0 | my $name = $self->getName(); | |||||||||
| 107 | 0 | my $line = $self->trim($self->{currentLine}); | |||||||||
| 108 | 0 | return "in $name at '$line', line $self->{currentLineNumber}"; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | #=============================================================================================== | ||||||||||
| 112 | # Protected Methods - Don't even think about calling these from outside the class. | ||||||||||
| 113 | #=============================================================================================== | ||||||||||
| 114 | |||||||||||
| 115 | sub _parseLines | ||||||||||
| 116 | 1 | ▶ | { | ||||||||
|
Subroutine
_parseLines: called CC=2 SCAR=6.9
| |||||||||||
| 117 | 1 | my $self = shift; | |||||||||
| 118 | 1 | my @lines = @_; | |||||||||
| 119 | 1 | my @commands; | |||||||||
| 120 | 1 | foreach my $line (@lines) | |||||||||
| 121 | { | ||||||||||
| 122 | 3 | push @commands, $self->_parseLine($line); | |||||||||
| 123 | } | ||||||||||
| 124 | 1 | return @commands; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | sub _parseLine | ||||||||||
| 128 | 12 | ▶ | { | ||||||||
|
Subroutine
_parseLine: called CC=2 SCAR=7.0
| |||||||||||
| 129 | 12 | my ($self, $line) = @_; | |||||||||
| 130 | |||||||||||
| 131 | 12 | my $tokenizer = new PerlActor::LineTokenizer(); | |||||||||
| 132 | 12 | my @tokens = $tokenizer->getTokens($line); | |||||||||
| 133 | |||||||||||
| 134 | 12 | ▶ | return unless @tokens; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | |||||||||||
| 136 | 12 | my $factory = new PerlActor::CommandFactory(); | |||||||||
| 137 | 12 | my $command = $factory->create(@tokens); | |||||||||
| 138 | |||||||||||
| 139 | 12 | return $command; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | sub _processLines | ||||||||||
| 143 | 6 | ▶ | { | ||||||||
|
Subroutine
_processLines: called CC=2 SCAR=6.9
| |||||||||||
| 144 | 6 | my $self = shift; | |||||||||
| 145 | |||||||||||
| 146 | 6 | $self->{currentLineNumber} = 0; | |||||||||
| 147 | 6 | foreach my $line (@{$self->{lines}}) | |||||||||
| 148 | { | ||||||||||
| 149 | 9 | $self->_processLine($line); | |||||||||
| 150 | } | ||||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | sub _processLine | ||||||||||
| 154 | 9 | ▶ | { | ||||||||
|
Subroutine
_processLine: called CC=2 SCAR=7.0
| |||||||||||
| 155 | 9 | my ($self, $line) = @_; | |||||||||
| 156 | 9 | chomp $line; | |||||||||
| 157 | 9 | $self->{currentLine} = $line; | |||||||||
| 158 | 9 | $self->{currentLineNumber}++; | |||||||||
| 159 | 9 | my $command = $self->_parseLine($line); | |||||||||
| 160 | 9 | ▶ | return unless $command; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 161 | 9 | $self->executeCommand($command); | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | # Keep Perl happy. | ||||||||||
| 165 | 1 | 1; | |||||||||