#! /usr/bin/perl # # FXController # the controller for the FX Arbitrage appliation # mediates interaction between the Model (FXEngine, FXData) # and the View (index.pl) # # package FXController; use FXData; use FXSessionManager; use FXEngine; use strict; # constructor FXController(FXSession object) sub new { my $class = shift; my $self = {}; $self->{fxsession} = shift; $self->{fxdata} = undef; $self->{limit} = 5; bless ($self, $class); $self->_initialize(); return $self; } # instantiates FXData object sub _initialize { my $self = shift; $self->{fxdata} = $self->{fxsession}->fxdata_factory(); } # udpates currency data using FXData sub update_data { my $self = shift; $self->{fxdata}->sync_rates(); } # # Public Methods # # currency_listing() # returns a hash of currency symbols and their descriptions # available to the user. # { SYMBOL1 => DESCRIPTION1, ... } sub currency_listing { my $self = shift; return %{$self->{fxdata}->currency_listing()}; } # do_update(bool) # if true updates currency data sub do_update { my $self = shift; my $bool = shift; $self->update_data() if $bool; } # set_table_limit(int) # determines the size of the # arbitrage table listing given to the view sub set_table_limit { my $self = shift; $self->{limit} = shift; } # arbitrage_table(start, array) -> string # start - the currency that starts every currency transaction # array - array of currency symbols used in the arbitrage table # returns a string of possible fx arbitrage transactions. sub aribitrage_table { my $self = shift; my $start = shift; my @currencies = @_; @currencies = grep { $_ ne $start } @currencies; unshift @currencies, $start; my $fxe = new FXEngine($self->{fxdata}, \@currencies); $fxe->set_limit($self->{limit}-1); return join "
", $fxe->get_transactions(); } 1;