File Coverage

blib/lib/AxKit/XSP/Exception.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             # $Id: Exception.pm,v 1.9 2002/06/11 07:44:30 matt Exp $
2              
3             package AxKit::XSP::Exception;
4              
5 1     1   1442 use strict;
  1         2  
  1         36  
6 1     1   1425 use Apache::AxKit::Language::XSP;
  0            
  0            
7              
8             use vars qw/@ISA $NS $VERSION $ForwardXSPExpr @E_state/;
9              
10             @ISA = ('Apache::AxKit::Language::XSP');
11             $NS = 'http://axkit.org/NS/xsp/exception/v1';
12              
13             $VERSION = "1.6";
14              
15             sub start_document{
16             my ($e) = shift;
17             @E_state = ();
18             return;
19             }
20              
21             sub parse_char {
22             my ($e, $text) = @_;
23             return '';
24             }
25              
26             my $sort_nodes = ' for ($parent->childNodes()) { $_->unbindNode; $real_parent->appendChild($_); } ';
27              
28             sub parse_start {
29             my ($e, $tag, %attribs) = @_;
30            
31             if ($tag eq 'try') {
32             $e->manage_text(0);
33             push(@E_state, "try");
34             return 'eval { my $real_parent = $parent; my $parent = $document->createElement("psuedo-parent"); '. "\n";
35            
36             }
37             elsif ($tag eq 'catch') {
38             $e->manage_text(0);
39             my $state = pop(@E_state);
40             if($state eq 'try') {
41             if(my $class = $attribs{'class'}) {
42             push(@E_state, 'catch');
43             return "$sort_nodes\n };\n".' if($@) { my $exception = $@; if($@->isa("'.$class.'")) { ';
44             }
45             else {
46             push(@E_state, 'catchall');
47             return "$sort_nodes\n };\n".' if($@) { my $exception = $@; ';
48             }
49             }
50             elsif($state eq 'catch') {
51             if(my $class = $attribs{'class'}) {
52             push(@E_state, 'catch');
53             return '} elsif($@->isa("'.$class.'")) { ';
54             }
55             else {
56             push(@E_state, 'catchelse');
57             return '} else { ';
58             }
59             }
60             else {
61             die "catch can only be called after a try tag";
62             }
63             }
64             elsif ($tag eq 'message') {
65             $e->start_expr($tag);
66             return '';
67             }
68             else {
69             die "Unknown exceptions tag: $tag";
70             }
71             }
72              
73             sub parse_end {
74             my ($e, $tag) = @_;
75             if ($tag eq 'try') {
76             my $state = pop(@E_state);
77             if($state eq 'try') {
78             # Not sure this is right - surely if you wrap the whole thing
79             # in a try block, with no catch, you just want to ignore the
80             # exceptions?
81             return $sort_nodes.'}; if($@) { die($@) }; '; # No if($@) block
82             }
83             elsif($state eq 'catch') {
84             return '} else { die($@) } }; undef($@); '; # if($@) { block --propogate die
85             }
86             elsif($state eq 'catchall') {
87             return '} undef($@); '; # if($@) { block -- don't propogate die
88             }
89             elsif($state eq 'catchelse') {
90             return '}} undef($@); '; #if($@) {} else { block -- don't propogate die
91             }
92             }
93             elsif ($tag eq 'catch') {
94             $e->manage_text(0);
95             return '';
96             }
97             elsif ($tag eq 'message') {
98             $e->append_to_script('$exception');
99             $e->end_expr();
100             return '';
101             }
102             }
103              
104             1;
105             __END__