| 1 | package Finance::GeniusTrader::Analyzers::Report; | ||
| 2 | |||
| 3 | # Copyright 2004 Oliver Bossert | ||
| 4 | # This file is distributed under the terms of the General Public License | ||
| 5 | # version 2 or (at your option) any later version. | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | |||
| 9 | use Finance::GeniusTrader::Analyzers::Process; | ||
| 10 | |||
| 11 | use Cwd; | ||
| 12 | use File::Spec; | ||
| 13 | use HTML::Mason; | ||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | Finance::GeniusTrader::Analyzers Report | ||
| 18 | |||
| 19 | =head2 DESCRIPTION | ||
| 20 | |||
| 21 | This module is mainly a wrapper to process a report file with | ||
| 22 | HTML::Mason. | ||
| 23 | |||
| 24 | This module needs HTML::Mason to display the reports and | ||
| 25 | Cwd and File::Spec to find out the actual path. | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | ############################################################ | ||
| 30 | sub new { # Generate a new Object | ||
| 31 | ############################################################ | ||
| 32 | my $type = shift; | ||
| 33 | my $class = ref($type) || $type; | ||
| 34 | my $self = {}; | ||
| 35 | bless $self, $class; | ||
| 36 | |||
| 37 | my $proc = shift; | ||
| 38 | if ( defined($proc) && ref($proc) =~ /Process/ ) { | ||
| 39 | $self->{'proc'} = $proc; | ||
| 40 | } else { | ||
| 41 | $self->{'proc'} = Finance::GeniusTrader::Analyzers::Process->new(); | ||
| 42 | } | ||
| 43 | return $self; | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | ############################################################ | ||
| 48 | sub interpret { | ||
| 49 | ############################################################ | ||
| 50 | my $self = shift; | ||
| 51 | my $filename = shift; | ||
| 52 | my @commands = @_; | ||
| 53 | my $output; | ||
| 54 | my $root = File::Spec->rel2abs( cwd() ); | ||
| 55 | my $interp = HTML::Mason::Interp->new( comp_root => $root, | ||
| 56 | out_method => \$output | ||
| 57 | ); | ||
| 58 | |||
| 59 | foreach ( @commands ) { | ||
| 60 | print STDERR $self->{'proc'}->parse( $_ ); | ||
| 61 | } | ||
| 62 | |||
| 63 | $interp->exec( '/' . $filename, | ||
| 64 | proc => $self->{'proc'} ); | ||
| 65 | |||
| 66 | return $output; | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; |