File Coverage

blib/lib/ExtUtils/Typemaps/MagicBuf.pm
Criterion Covered Total %
statement 9 14 64.2
branch n/a
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 19 68.4


line stmt bran cond sub pod time code
1             package ExtUtils::Typemaps::MagicBuf;
2             $ExtUtils::Typemaps::MagicBuf::VERSION = '0.009';
3 1     1   178004 use strict;
  1         3  
  1         51  
4 1     1   6 use warnings;
  1         2  
  1         99  
5              
6 1     1   25 use parent 'ExtUtils::Typemaps';
  1         8  
  1         11  
7              
8             sub new {
9 0     0 1   my $class = shift;
10 0           my $self = $class->SUPER::new(@_);
11              
12 0           $self->add_inputmap(xstype => 'T_MAGICBUF', code => <<'END');
13             {
14             SV* arg = $arg;
15             MAGIC* magic = SvROK(arg) && SvRMAGICAL(SvRV(arg)) ? mg_findext(SvRV(arg), PERL_MAGIC_ext, NULL) : NULL;
16             if (magic)
17             $var = ($type)magic->mg_ptr;
18             else
19             Perl_croak(aTHX_ \"%s object is lacking magic\", \"$ntype\");
20             }
21             END
22              
23 0           $self->add_outputmap(xstype => 'T_MAGICBUF', code => <<'END');
24             {
25             MAGIC* magic = sv_magicext(newSVrv($arg, "$ntype"), NULL, PERL_MAGIC_ext, NULL, (const char*)$var, 0);
26             magic->mg_len = sizeof(*$var);
27             }
28             END
29              
30 0           return $self;
31             }
32              
33             1;
34              
35             # ABSTRACT: Typemap for storing objects in magic buffer
36              
37             __END__