The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Finance::Bitcoin::Feed::Site - Base class of Finance::Bitcoin::Feed::Site::* modules

SYNOPSIS

    use Mojo::Base 'Finance::Bitcoin::Feed::Site';
    has site => 'SITENAME';


    sub go{
       my $self = shift;
       #Dont' forget this line:
       $self->SUPER::go();
       # connect the site
       # parse the data
       # and emit the data by call
       $self->emit('data_out', $currency, $price);
    }

DESCRIPTION

It is a base class. It set some helper attributes and methods, and have an timer event that can restart the connection. You just need to override the method 'go' to connect to the site.

ATTRIBUTES

This class inherits all attributes from Mojo::EventEmitter and add the following new ones:

last_activity_at

The time that the object receive the data from the server. It is mainly updated by the method 'on_data_out'

last_activity_period

if time() - last_activity_at > last_activity_period, then we think the site is disconnected.

timer

The timer event to restart the connection

started

The tag that shows the site is running.

site

The site name which will be print in the debug information.

METHODS

new

Create object and set some events and timer

on_data_out

the callback which will be called when receive the event 'data_out'. It will Then emit the event 'output'

The args of event data_out is:

    my ($self, $timestamp, $site, $currency, $price) = @_;

The unit of timestamp is ms.

timer_call_back

The callback called by timer. It will emit event 'timeout' when timeout.

set_timeout

is_timeout

on_timeout

The callback of event 'timeout'. It will call method 'go' to restart the connection

go

Establish the connection.

debug

Print debug information if the envrionment variable 'FINANCE_BITCOIN_FEED_DEBUG' is set to true.

error

Print error information if there is error.

EVENTS

This class inherits all events from Mojo::EventEmitter and add the following new ones:

data_out

It will be emitted by the site module when the site module want to output the data.

output

It will be emit by this module when print out the data. You can listen on this event to get the output.

timeout

It will be emit when the timer watch that the connection is timeout

SEE ALSO

Mojo::EventEmitter

Finance::Bitcoin::Feed

AUTHOR

Chylli <chylli@binary.com>