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

NAME

Business::ISP::Object - This module is the base class for all other modules under the Business::ISP:: umbrella.

SYNOPSIS

    use Business::ISP::Transac; # does not override new()
    use Business::ISP::User;    # overrides new

    # Instantiate a new object who's class does not provide a new() method
    my $transaction = Business::ISP::Transaction->new();

    # Load in info from the config file if the object's class overrides the
    # new() method
    my $user = Business::ISP::User->new();
    $user->configure();
    

DESCRIPTION

This module contains base methods common to multiple other classes. All Business::ISP:: modules should use this class as it's base class.

METHODS

new({ config => config_file_location })

Provides instantiation of an object of classes who only need generic initialization.

Parameters must be passed in as a hash reference.

configure ({ NAME => VALUE })

For classes that must override the new() method due to instance specific initialization, this method will configure the existing object with information from the configuration file, if it exists.

There are two optional named parameters that can be passed in as a hash reference:

    config      => '/path/to/file',
    more_config => '/path/to/additional.config/'

If config is not passed in, the default configuration file will be used.

The more_config parameter allows the caller to specify an additional file that contains configuration information that will be applied in addition to the primary config.

Returns 1 if neither the default or the passed in parameter configuration files can be found or read.

Returns 0 upon success.

date ( { get => VALUE, datetime => $datetime } )

Returns a date string or object.

The 'get' hashref parameter can take either day, month or year as valid values.

If year is specified, returns the string 'YYYY'. If 'month' is specified, the return is 'YYYY-MM'. For day, returns 'YYYY-MM-DD'.

The method will generate a 'now' DateTime object to work with, unless a pre-created DateTime object is passed in with the 'datetime' parameter.

Returns a DateTime object of the present date/time if no parameters are passed in.

The program terminates via croak() if the 'get' parameter is passed in with an invalid value.

function_orders

Call this method in each and every caller where you want to keep the state of the running application.

This method is used to perform global operations, such as stack tracing, profiling, codeflow rendering etc.

All methods in all classes in the Business::ISP:: umbrella call this method just after shifting $self.

Takes no parameters, and it has no return.

build_stack ({ stack_file => 'file_location' })

A method using Storable to create a stack trace. All methods across all classes should be configured to use this method, with control in the config file.

The default stack storage file is /tmp/stack.txt. This can be overridden using the 'stack_file' parameter, passed in as a hash reference.

db_handle

Creates a database handle for DBI.

All configuration info for the DBH is retrieved from the config file. If 'in_test_mode' is set in the config file, a database handle that points to the testing database will be configured.

Returns the DBH as a hash ref upon success.

dsn ({ table => table_name })

Creates a data source for methods that use DBIx::Recordset.

'table' is a mandatory scalar string which indicates which table in the database to work with. The parameter is passed in as a hash reference.

The rest of the DSN is configured from the configuration file.

Returns the DSN as a hash upon success.

The table name will be returned within the DSN as undef if the table parameter is not supplied.

schema ({ result => RESULT, extract => EXTRACT })

Returns a DBIx::Class object that has been pre-configured with the data source information for the ISP database, with the added capability of configuring a result with an inflator.

When called with no parameters, returns $schema, which is ready to be used directly, eg:

    $obj->schema();
    $schema->resultset( 'Clients' )->(1)

If an inflation method is desired for the results of a schema call, both RESULT and EXTRACT parameters are mandatory, and must be passed in within a hash reference.

RESULT is the reference that is returned by a call to resultset(). EXTRACT is the code for the inflation module to use. Currently, the only EXTRACT parameter valid is href.

Returns undef if the parameters are incorrect, returns $schema otherwise.

database_config

This method compiles all of the database information from the configuration file.

It returns an array reference. Each element of the returned array ref is another array reference, containing the database connectivity information. If 'in_test_mode' is enabled in the configuration file, only the test database information will be returned. Otherwise, the first element will be the master server configuration, and the following will be the slaves.

[ 'db_source', 'db_user', 'db_pass' ]

If "master_locked" is set in the config file, the master server will not be included in the return, and the first slave server will be used instead, if available. Note that the system operates in read-only mode while the master server is locked.

An empty array reference will be returned if configuration fails, or no database configuration details are present in the configuration file.

item_count({ date => DATE, column => COLUMN })

Used to get a list of all the different entries in a single column from any one of our database tables.

TABLE is a mandatory scalar string. This parameter is used to determine which table in the database to look into. Valid table names are Balance, Uledger, Notes, Gledger, Bank, Operator, Receipt, Plans, Clients and Audit. The names are case-sensitive.

DATE is an optional scalar string param, in the following format YYYY-MM-DD. Note that you don't need to use the entire date, YYYY will work for year, and YYYY-MM will work for a month. If DATE is not supplied, all records in the table will be counted.

COLUMN is a scalar string of the column you want the data from. Both params must be passed in within a hash reference.

Returns a hash reference where the keys are the field names found, and the value for each key is an integer representing the number of times that field was found.

tax_rate ( TAX )

Returns the applicable tax rate out of the config file.

The manadory parameter TAX is a scalar string, containing one of 'pst' or 'gst'.

Returns undef if a tax type is not supplied as a param, or the tax type is not found.

bank_info ({ config => 'config_file_location' })

This method retrieves the information necessary to authenticate to the credit card processor, and process credit card payments/refunds.

The information is retrieved from the configuration file.

An optional parameter pointing to an alternate configuration file can be passed in as a hash reference.

It is important to note that unless BANK_TEST_MODE is set to 1 in the configuration file, merchant processing will happen live-time in production.

Returns the bank login info as a hash ref.

string_date

Returns the current date in stringified form, eg: Jun 1, 2009

Takes no params, returns a scalar string.

string_to_date ( DATE )

This method converts a stringified date, eg: Jun 1, 2009 and converts it into the format 2009-06-01.

DATE is a mandatory string scalar, which contains the stringified date you want converted.

Returns the reformatted date as a scalar string.

full_date

Call this method when you need a stringified date in MySQL format, eg:

    '2009-08-12 HH:MM:SS'

Takes no parameters, returns the stringified date.

storeit ({ data => some_ref, store => 'name_of_storage_file' })

Using Storable, will store data into the specified file for later retrieval.

'data' and 'store' are to be passed in as a hash reference.

'data' is any type of data structure. 'store' is a string scalar file name.

Returns 1 if 'store' is not provided.

Returns 0 upon success.

retrieveit ({ store => 'name_of_store_file' })

Using Storable, will retrieve the data that was stowed by storeit().

'store' is the path to the file the data is in. Pass it in as a hash reference.

Returns 1 if 'store' is not present, or the file doesn't exist or can't be opened.

Returns a scalar containing the reference of the data.

It's up to the caller to sort out the reference type.

captcha ({ NAME => VALUE })

This method is used to generate random captchas, and to compare user input against it.

Called with no params, will return a random integer. The length of the integer is determined by the 'captcha_length' directive in the configuration file.

To compare the captcha with the user's input, pass in the following two parameters as a hash reference.

    captcha => $captcha,
    input   => $user_input

Where $captcha is the captcha originally supplied in the initial call, and $input is what the user supplied. Returns "ok" upon successful match.

If one but not both of the parameters are missing, or if the captcha does not equal the input, returns 0.

GET_CODEFLOW

If the config file variable CODEFLOW is enabled, this sub will return an array which contains the entire method process flow of the current run.

Takes no parameters.

AUTHOR

Steve Bertrand, <steveb at cpan.org>

BUGS

Report bugs to <steve at ibctech.ca>. I will be notified, and will report back to you with any updates.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Business::ISP::Object

COPYRIGHT & LICENSE

Copyright 2012 Steve Bertrand, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.