| 1 | # Copyright 2011-2012 Yuki Izumi. ( anneli AT cpan DOT org ) | ||||||||||||||||||||||||||||
| 2 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||
| 3 | # same terms as Perl itself. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Erlang::Parser::Node::Try; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | with 'Erlang::Parser::Node'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | has 'exprs' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); | |||||||||||||||||||||||||||
| 11 | 3 | has 'of' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node::Alt]]'); | |||||||||||||||||||||||||||
| 12 | 3 | has 'catch' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node::Alt]]'); | |||||||||||||||||||||||||||
| 13 | 3 | has 'aft' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node]]'); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 62 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 62 | my ($self, $fh, $depth) = @_; | |||||||||||||||||||||||||||
| 17 | 62 | ▶ | $depth ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$depth ||= 0
MC/DC0%0/1
$depth ||= 0
$depth
Truth table50%1/2
A
A= $depth
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 62 | print $fh "try\n"; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 62 | $depth++; | |||||||||||||||||||||||||||
| 22 | 62 | print $fh "\t" x $depth; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 62 | my $first = 1; | |||||||||||||||||||||||||||
| 25 | 62 | foreach (@{$self->exprs}) { | |||||||||||||||||||||||||||
| 26 | 90 | ▶ | if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 90 | $_->print($fh, $depth); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 62 | $depth--; | |||||||||||||||||||||||||||
| 31 | 62 | print $fh "\n", "\t" x $depth; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 62 | ▶ | if (defined $self->of and @{$self->of}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->of and @{$self->of;}
MC/DC50%1/2
defined $self->of and @{$self->of;}
defined $self->of
@{$self->of;}
Truth table66%2/3
A and B
A= defined $self->ofB= @{$self->of;}
| |||||||||||||||||||||||||||||
| 34 | 2 | print $fh "of\n"; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | $depth++; | |||||||||||||||||||||||||||
| 37 | 2 | print $fh "\t" x $depth; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | my $first = 1; | |||||||||||||||||||||||||||
| 40 | 2 | foreach (@{$self->of}) { | |||||||||||||||||||||||||||
| 41 | 4 | ▶ | if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 4 | $_->print($fh, $depth); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | $depth--; | |||||||||||||||||||||||||||
| 46 | 2 | print $fh "\n", "\t" x $depth; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 62 | ▶ | if (defined $self->catch and @{$self->catch}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->catch and @{$self->catch;}
MC/DC50%1/2
defined $self->catch and @{$self->catch;}
defined $self->catch
@{$self->catch;}
Truth table66%2/3
A and B
A= defined $self->catchB= @{$self->catch;}
| |||||||||||||||||||||||||||||
| 50 | 52 | print $fh "catch\n"; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 52 | $depth++; | |||||||||||||||||||||||||||
| 53 | 52 | print $fh "\t" x $depth; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 52 | my $first = 1; | |||||||||||||||||||||||||||
| 56 | 52 | foreach (@{$self->catch}) { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 52 | $_->print($fh, $depth); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 52 | $depth--; | |||||||||||||||||||||||||||
| 62 | 52 | print $fh "\n", "\t" x $depth; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 62 | ▶ | if (defined $self->aft and @{$self->aft}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->aft and @{$self->aft;}
MC/DC50%1/2
defined $self->aft and @{$self->aft;}
defined $self->aft
@{$self->aft;}
Truth table66%2/3
A and B
A= defined $self->aftB= @{$self->aft;}
| |||||||||||||||||||||||||||||
| 66 | 10 | print $fh "after\n"; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 10 | $depth++; | |||||||||||||||||||||||||||
| 69 | 10 | print $fh "\t" x $depth; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 10 | my $first = 1; | |||||||||||||||||||||||||||
| 72 | 10 | foreach (@{$self->aft}) { | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 10 | $_->print($fh, $depth); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 10 | $depth--; | |||||||||||||||||||||||||||
| 78 | 10 | print $fh "\n", "\t" x $depth; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 62 | print $fh "end"; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 NAME | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Erlang::Parser::Node::Try - a try/catch clause | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | A clause to catch exceptions. A block of expressions is evaluated; the last | ||||||||||||||||||||||||||||
| 93 | expression's value is optionally then matched against patterns and guards, and | ||||||||||||||||||||||||||||
| 94 | then a further block of statements executed. Exceptions raised therein can be | ||||||||||||||||||||||||||||
| 95 | caught in the catch clause. Finally, cleanup statements can be invoked. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 Accessors | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =over 4 | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item C<exprs> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | A list of L<Erlang::Parser::Node>s; the last expression's value is that used in | ||||||||||||||||||||||||||||
| 104 | the of clause. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =item C<of> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | An optional list of L<Erlang::Parser::Node::Alt>s against which the last | ||||||||||||||||||||||||||||
| 109 | expression in C<exprs> is matched. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =item C<catch> | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | An optional list of L<Erlang::Parser::Node::Alt>s for exceptions raised during | ||||||||||||||||||||||||||||
| 114 | evaluation in C<exprs> and C<of>. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item C<aft> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | An optional list of L<Erlang::Parser::Node>s, executed after all previous | ||||||||||||||||||||||||||||
| 119 | statements. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head2 Methods | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =over 4 | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =item C<print> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Pretty-prints the node to its filehandle argument. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head1 EXAMPLE | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | try | ||||||||||||||||||||||||||||
| 136 | {ok, X} = my_fun(), | ||||||||||||||||||||||||||||
| 137 | binary_to_term(X) | ||||||||||||||||||||||||||||
| 138 | catch | ||||||||||||||||||||||||||||
| 139 | throw:Term -> Term | ||||||||||||||||||||||||||||
| 140 | after | ||||||||||||||||||||||||||||
| 141 | file:close(F) | ||||||||||||||||||||||||||||
| 142 | end | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 3 | 1; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # vim: set sw=4 ts=4: | ||||||||||||||||||||||||||||