File Coverage

lib/ExtUtils/XSpp/Exception/perlcode.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 4 50.0
condition 2 6 33.3
subroutine 6 6 100.0
pod 1 2 50.0
total 39 46 84.7


line stmt bran cond sub pod time code
1             package ExtUtils::XSpp::Exception::perlcode;
2 21     21   125 use strict;
  21         42  
  21         700  
3 21     21   111 use warnings;
  21         37  
  21         767  
4 21     21   110 use base 'ExtUtils::XSpp::Exception';
  21         44  
  21         1454  
5              
6 1 50 33 1   20 sub _dl { return defined( $_[0] ) && length( $_[0] ) ? $_[0] : undef }
7              
8             sub init {
9 1     1 0 2 my $this = shift;
10 1         7 $this->SUPER::init(@_);
11 1         2 my %args = @_;
12              
13 1   33     10 $this->{PERL_CODE} = _dl( $args{perl_code} || $args{arg1} );
14             }
15              
16             sub handler_code {
17 1     1 1 3 my $this = shift;
18 1         3 my $no_spaces_indent = shift;
19 1 50       4 $no_spaces_indent = 4 if not defined $no_spaces_indent;
20              
21 1         12 my $ctype = $this->cpp_type;
22 1         3 my $pcode = $this->{PERL_CODE};
23 1         4 $pcode =~ s/^\s+//;
24 1         4 $pcode =~ s/\s+$//;
25 1         3 $pcode =~ s/\\/\\\\/g;
26 1         136 $pcode =~ s/"/\\"/g;
27 1         7 my @lines = split /\n/, $pcode;
28 1         4 $pcode = '"' . join(qq{"\n"}, @lines) . qq{"};
29 1         9 $pcode = $this->indent_code($pcode, 4);
30 1         3 my $code = <
31             catch ($ctype& e) {
32             SV* errsv;
33             SV* excsv;
34             excsv = eval_pv(
35             $pcode,
36             1
37             );
38             errsv = get_sv("@", TRUE);
39             sv_setsv(errsv, excsv);
40             croak(NULL);
41             }
42             HERE
43 1         4 return $this->indent_code($code, $no_spaces_indent);
44             }
45              
46             1;