| 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__ |