LP/Object.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 CC 3 SCAR 17.5
CC
3
Cov
0%
croak
12.0
new
2.0
initialize
2.0
CRAP 5.8
1 package Math::LP::Object;
2 use strict;
3 use fields qw();
4  
5 sub new { # constructs a new object
6 my $pkg = shift;
7 no strict 'refs';
8 my Math::LP::Object $this = fields::new($pkg);
9 my %arg = @_;
10 while(my($k,$v) = each %arg) { $this->{$k} = $v; }
11 $this->initialize();
12 return $this;
13 }
14 sub initialize { # override in derived classes
15 1;
16 }
17 sub croak { # trace an error coming from outside the Math::LP functions
18 shift if defined(ref $_[0]); # invoked on object
19 for(my $i = 1; $i < 9999; ++$i) { # 9999 is an arbitrary upper limit
20 my ($cpkg,$cfile,$cline,$csub) = caller($i);
21 if($cpkg !~ /^Math::LP/) { # found the evil caller
22 my $msg = join '', @_;
23 chomp $msg;
24 die $msg, " in $csub at line $cline of $cfile.\n";
25 }
26 }
27 }
28  
29 1;
30  
31 __END__