The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Finance::Shares::Support - Miscellaneous functions

SYNOPSIS

    use Finance::Shares::Support qw(
            today_as_string
            string_from_ymd
            ymd_from_string
            increment_days
            increment_date
            days_difference
            day_of_week
        );

 

DESCRIPTION

deep_copy( var )

var is returned unless it is, or contains, a hash ref or an array ref. These are copied recursively and the copy is returned.

name_split( name )

Returns the list of fields. Of course if a partial name is given the name is split accordingly. Typical results are

    (sample, stock, period, fntag, line)
    (sample, stock, period, fntag)
    (fntag, line)
    (fntag)
    

name_join( list )

Returns a string containing a canonical name for a Finance::Shares object.

The list of strings must be in the correct order:

    sample, stock, period, function, line.
    

The canonical name for the parent plus the child object ID is also acceptable.

name_flatten( name, char )

Remove seperator characters ('/') from name, replacing them with char.

shown_style( value )

Return a list ($shown, $style) depending on the value given.

'0'

The line is hidden. Returns (0, undef).

'1'

The line is visible with the default style. Returns (1, undef).

hash ref

The line uses a style created from this specification. Returns (1, hashref).

PostScript::Graph::Style object

The line is shown with the style given. Returns (1, object).

DATE FUNCTIONS

There are three types of dates here. A 'days' value is the number of days from some arbitrary day zero. A 'date' is a string in YYYY-MM-DD format while 'ymd' refers to an array holding a year, month and day such as (2002, 12, 31). See SYNOPSIS for all the functions.

today_as_string

Return today's date in YYYY-MM-DD format.

string_from_ymd( year, month, day )

Convert the numeric representation of year, month and day into a YYYY-MM-DD date.

ymd_from_string( date )

Convert a YYYY-MM-DD date into an array of numeric values in the form:

    (year, month, day)

increment_ymd( year, month, day, inc, period )

Add inc periods to the date and return as a year-month-day array. period can be one of quotes, weekdays, days, weeks or months.

decrement_ymd( year, month, day, dec, period )

Subtract dec periods to the date and return as a year-month-day array. period can be one of quotes, weekdays, days, weeks or months.

increment_date( date, inc, period )

Add inc periods to the YYYY-MM-DD date and return the new date in YYYY-MM-DD format. period can be one of quotes, weekdays, days, weeks or months.

decrement_date( date, dec, period )

Subtract dec periods to the YYYY-MM-DD date and return the new date in YYYY-MM-DD format. period can be one of quotes, weekdays, days, weeks or months.

days_difference( year1, month1, day1, year2, month2, day2 )

Return the number of days between the two dates

day_of_week( year, month, day )

Returns 1=Monday, ... 7=Sunday.

DEBUGGING

out(obj, lvl, msg)

Send a message to STDERR if the verbosity setting is greater than or equal to lvl. msg can be a list or a single string, like print.

obj must have {verbose} field.

out_indent( inc )

Make a relative change to the depth of indentation used by out and outf.

show_addresses ( [arg] )

Determines whether show displays structure addresses. These are useful in complex structires as each hash or array ref is shown only once. arg should be 1 or 0. (Default: 1)

show_indent( [string [, regexp]] )

This declares the string show uses for one indent. The optional regular expression is required if string uses characters such as '|' which have special meanings. If the indent string can't be matched, closing brackets aren't aligned correctly. (Default: ': ')

show( msg, var )

Uses warn to output the message followed by show_deep($var, $level).

show_deep( var [, min [, sep]] )

NOTE this is an exported function, not a method.

Recursively dumps hash or array refs, returning a string which may be displayed with e.g. warn. Normally only plain hashes or arrays are expanded. However, by setting the exported variable @show_objects to a list of classes, all such objects are expanded, too.

var

The scalar variable to be printed.

min

A limit to the depth printed out.

sep

String used to seperate entries (between pairs, not within them).

Example

    warn "MyModule:666\n", show_deep($h, 2);

might produce something like the following, with 2 levels (chart1, and background etc.). Deeper arrays and hashes are not expanded.

    {chart1=>
      {background=>ARRAY(0x87573cc),
      dots_per_inch=>75, invert=>1, 
      key=>HASH(0x87547a4)}
    

show_dump( [values...], [names...] )

Calls Data::Dumper on values passed. Returns a string which may be displayed with e.g. warn.

check_filesize( filename, filesizes [, $write] )

Returns 1 if the named file is the size recorded in the file filesizes, 0 if the size is different.

If files doesn't exist or the name is not found, 1 is returned but warnings are given. write is assumed unless it is set to 0.

AUTHOR

Chris Willmot, chris@willmot.org.uk

SEE ALSO

Finance::Shares::MySQL, Finance::Shares::Chart and Finance::Shares::Model.

There is also an introduction, Finance::Shares::Overview and a tutorial beginning with Finance::Shares::Lesson1.