File Coverage

blib/lib/Language/Befunge/Storage/Generic/Vec/XS.pm
Criterion Covered Total %
statement 40 40 100.0
branch 6 6 100.0
condition 4 6 66.6
subroutine 10 10 100.0
pod 3 3 100.0
total 63 65 96.9


line stmt bran cond sub pod time code
1             #
2             # This file is part of Language::Befunge::Storage::Generic::Vec::XS.
3             # Copyright (c) 2008 Mark Glines, all rights reserved.
4             #
5             # This program is licensed under the terms of the Artistic License v2.0.
6             # See the "LICENSE" file for details.
7              
8              
9             package Language::Befunge::Storage::Generic::Vec::XS;
10              
11 3     3   133882 use strict;
  3         10  
  3         128  
12 3     3   19 use warnings;
  3         6  
  3         110  
13 3     3   15 no warnings 'redefine';
  3         11  
  3         190  
14              
15             our $VERSION = '0.03';
16              
17 3     3   18 use base 'Language::Befunge::Storage::Generic::Vec';
  3         7  
  3         2615  
18 3     3   71063 use Language::Befunge::Vector;
  3         6  
  3         1213  
19              
20             require XSLoader;
21             XSLoader::load('Language::Befunge::Storage::Generic::Vec::XS', $VERSION);
22              
23             # Preloaded methods go here.
24              
25             sub get_value {
26 1375     1375 1 81529 my ($self, $v) = @_;
27 1375         3003 my ($min, $max, $nd) = @$self{qw(min max nd)};
28 1375 100       5026 return 32 unless $v->bounds_check($min, $max);
29 1360         10625 my $rv = $self->_get_value($v, $$self{torus}, $min, $max, $nd);
30 1360         3475 return $rv;
31             }
32              
33              
34             sub set_value {
35 410     410 1 31343 my ($self, $v, $value) = @_;
36 410         724 my ($min, $max, $nd) = @$self{qw(min max nd)};
37 410 100       1462 unless($v->bounds_check($min, $max)) {
38 4         11 $self->expand($v);
39             # min/max were overwritten by expand()
40 4         10 ($min, $max) = @$self{qw(min max)};
41             }
42 410         1860 return $self->_set_value($v, $$self{torus}, $min, $max, $nd, $value);
43             }
44              
45              
46             sub _offset {
47 6     6   10 my ($self, $v, $min, $max) = @_;
48 6   66     28 $min //= $$self{min};
49 6   66     55 $max //= $$self{max};
50 6         99 return $self->__offset($$self{nd}, $v, $min, $max);
51             }
52              
53              
54             sub expand {
55 58     58 1 9552 my ($self, $point) = @_;
56 58         126 my ($omin, $omax, $nd) = @$self{qw(min max nd)};
57 58 100       225 return if $point->bounds_check($omin, $omax);
58 35         152 my ($min, $max) = ($omin->copy, $omax->copy);
59 35         74 my $torus = $$self{torus};
60 35         582 my $rv = $self->_expand($nd, $point->copy, $min, $max, $omin, $omax, $torus);
61 35         86 $$self{torus} = $rv;
62 35         56 $$self{min} = $min;
63 35         117 $$self{max} = $max;
64             }
65              
66              
67 1     1   3022 sub _is_xs { 1 }
68              
69             1;
70             __END__