JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / jpred / lib / Root.pm
1 package Root;
2
3 use strict;
4 use warnings;
5 use Carp;
6
7 # CC This lib path is unnecessary - commented out as supercedes the 'lib' use in jpred itself.
8 #use lib qw(/homes/jon/cvs/jon/jpred/src /homes/jon/usr/lib/perl5);
9
10 =head1 NAME 
11
12 Root - Base module for new classes to inherit from
13
14 =head1 DESCRIPTION
15
16 This modules provides a new method for other classes to use if they so wish.
17
18 =head1 METHODS
19
20 =head2 new(foo => "bar")
21
22 This constructs an object of the right class and returns it. Any arugments passed to the constructer will be parsed as a hash with the first argument from the pair acting as the method that should be called and the second being the argument for that method.
23
24 =cut
25
26 sub new {
27         my ($class, %args) = @_;
28         my $self = bless {}, ref($class) || $class;
29
30         for (keys %args) {
31                 croak "No such method '$_'" unless $self->can($_);
32                 $self->$_($args{$_});
33         }
34
35         return $self;
36 }
37
38 sub trace {
39         my ($self) = @_;
40
41         my $i = 1;
42
43         while (my @caller = caller $i) {
44                 #print join("#", map { defined $_ ? $_ : ""} @caller), "\n";
45                 print $caller[0], ":", $caller[2], " ", $caller[3], "\n";
46                 $i++;
47         }
48 }
49
50 sub warn {
51         my ($self, @message) = @_;
52         print STDERR join("\n", @message), "\n";
53         $self->trace;
54 }
55
56 1;