JPRED-2 Current state of the SVN trank
[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 
23 will be parsed as a hash with the first argument from the pair acting as the method that should 
24 be called and the second being the argument for that method.
25
26 =cut
27
28 sub new {
29   my ( $class, %args ) = @_;
30   my $self = bless {}, ref($class) || $class;
31
32   for ( keys %args ) {
33     croak "No such method '$_'" unless $self->can($_);
34     $self->$_( $args{$_} );
35   }
36
37   return $self;
38 }
39
40 sub trace {
41   my ($self) = @_;
42
43   my $i = 1;
44
45   while ( my @caller = caller $i ) {
46
47     #print join("#", map { defined $_ ? $_ : ""} @caller), "\n";
48     print $caller[0], ":", $caller[2], " ", $caller[3], "\n";
49     $i++;
50   }
51 }
52
53 sub warn {
54   my ( $self, @message ) = @_;
55   print STDERR join( "\n", @message ), "\n";
56   $self->trace;
57 }
58
59 1;