[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GT] Removing dependency on libxml when it is not used



Currently, GT requires the use of XML::LibXML regardless if you
actually need it or not.
For instance, the following command won't work if that library is not installed:

display_indicator.pl I:EMA EURUSD 200


This behaviour just seems silly, so i'm attaching a patch to get around this.


The way it works is to remove the Metainfo object from the Calculator
object and remove
use GT::Serializable from Prices.pm.

As far as I could tell only the EVWMA indicator actually uses the
Calculator->Metainfo,
so i'm patching that indicator as well.

Despite my limited testing i believe removing GT::Serializable from
Prices.pm doesn't
produce side effects, but if someone could apply this patch and run
some backtests storing
data to local files that would be a big help.

Regards,
Joao
Index: Indicators/EVWMA.pm
===================================================================
--- Indicators/EVWMA.pm	(revision 647)
+++ Indicators/EVWMA.pm	(working copy)
@@ -16,6 +16,7 @@
 
 use GT::Indicators;
 use GT::Prices;
+use GT::MetaInfo;
 
 @ISA = qw(GT::Indicators);
 @NAMES = ("EVWMA");
@@ -69,6 +70,12 @@
 =head2 GT::Indicators::EVWMA::calculate($calc, $day)
 
 =cut
+sub initialize {
+    my ($self) = @_;
+
+    $self->{'metainfo'} = GT::MetaInfo->new();
+}
+
 sub calculate {
     my ($self, $calc, $i) = @_;
     my $getvalue = $self->{'_func'};
@@ -84,8 +91,8 @@
     return if not (-e "/bourse/metainfo/" . $calc->code . ".xml");
        
     # Find the number of floating shares
-    $calc->metainfo->load("/bourse/metainfo/" . $calc->code . ".xml");
-    my $floating_shares = $calc->metainfo->get("floating_shares");
+    $self->{'metainfo'}->load("/bourse/metainfo/" . $calc->code . ".xml");
+    my $floating_shares = $self->{'metainfo'}->get("floating_shares");
     
     for (my $n = 0; $n <= $i; $n++) {
     
Index: Calculator.pm
===================================================================
--- Calculator.pm	(revision 647)
+++ Calculator.pm	(working copy)
@@ -5,7 +5,6 @@
 # version 2 or (at your option) any later version.
 
 use GT::CacheValues;
-use GT::MetaInfo;
 
 =head1 NAME
 
@@ -14,7 +13,7 @@
 =head1 DESCRIPTION
 
 This is a facility object to ease the collaboration between GT::Prices
-and GT::CacheValues and GT::MetaInfo. It contains the prices (GT::Prices),
+and GT::CacheValues. It contains the prices (GT::Prices),
 and the result of various indicators and signals within two GT::CacheValues
 object. This object is manipulated by all the indicators, signals and
 systems.
@@ -46,10 +45,6 @@
 Return the corresponding object of the indicated timeframe. Learn
 more about the timeframes in GT::DateTime.
 
-=item C<< $c->metainfo() >>
-
-Returns the metainfo object associated to the share.
-
 =item C<< $c->set_code($code) >>
 
 Sets the code of the share which datas are stored in this object.
@@ -71,8 +66,6 @@
     $self->{'tf'}{$prices->timeframe}{'indics'} = GT::CacheValues->new;
     $self->{'tf'}{$prices->timeframe}{'signals'} = GT::CacheValues->new;
     
-    $self->{'_metainfo'} = GT::MetaInfo->new();
-    
     bless $self, $class;
     
     $self->set_current_timeframe($prices->timeframe);
@@ -91,8 +84,6 @@
 sub indicators { $_[0]->{'_indics'}  }
 sub signals    { $_[0]->{'_signals'} }
 
-sub metainfo   { $_[0]->{'_metainfo'} }
-
 sub prices_on_timeframe     { $_[0]->{'tf'}{$_[1]}{'prices'} }
 sub indicators_on_timeframe { $_[0]->{'tf'}{$_[1]}{'indics'} }
 sub signals_on_timeframe    { $_[0]->{'tf'}{$_[1]}{'signals'} }
Index: Prices.pm
===================================================================
--- Prices.pm	(revision 647)
+++ Prices.pm	(working copy)
@@ -10,10 +10,9 @@
 use Date::Calc qw(Decode_Date_US Decode_Date_EU Today);
 #ALL#  use Log::Log4perl qw(:easy);
 use GT::DateTime;
-use GT::Serializable;
 
 require Exporter;
-
AT
ISA = qw(Exporter GT::Serializable);
+
AT
ISA = qw(Exporter);
 @EXPORT = qw($FIRST $OPEN $HIGH $LOW $LAST $CLOSE $VOLUME $DATE);
 
 $FIRST = $OPEN = 0;