NAME

SPOPS::Utility - Utility methods for SPOPS objects

SYNOPSIS

# In configuration file
 'isa' => [ qw/ SPOPS::Utility SPOPS::DBI / ],

# Create an object and run a utility
my $user = MyApp::User->fetch( $id );
$user->{crypted_password} = $user->crypt_it( $new_password );

# Also use them separately
use SPOPS::Utility qw();

my $now = SPOPS::Utility->now;
my $random = SPOPS::Utility->generate_random_code( 16 );

DESCRIPTION

This class has a number of utility methods that can be used from SPOPS objects or from the SPOPS classes. They were previously in the main SPOPS module but were removed to make the classes more consistent and focused.

The different methods are fairly unrelated.

METHODS

generate_random_code( $length )

Generates a random code of $length length consisting of upper-case characters in the english alphabet.

crypt_it( $text )

Returns a crypt()ed version of $text. If $text not passed in, returns undef.

now( \% )

Return the current time, formatted: yyyy-mm-dd hh:mm:ss. Since we use the Date::Format module (which in turn uses standard strftime formatting strings), you can pass in a format for the date/time to fit your needs.

Parameters:

  • format: strftime format

  • time: return of time command (or manipulation thereof); see perldoc -f time

today()

Return a date (yyyy-mm-dd) for today.

now_between_dates( { begin = $dateinfo, end => $dateinfo } );

Where $dateinfo is either a simple scalar ('yyyy-mm-dd') or an arrayref ([yyyy,mm,dd]).

Note that you can also just pass one of the dates and the check will still perform ok.

Returns 1 if 'now' is between the two dates (inclusive), undef otherwise.

Examples:

# Today is '2000-10-31' in all examples

SPOPS::Utility->now_between_days( { begin => '2000-11-01' } );
( returns 'undef' )

SPOPS::Utility->now_between_days( { end => '1999-10-31' } );
( returns 'undef' )

SPOPS::Utility->now_between_days( { begin => [2000, 10, 1 ] } );
( returns 1 )

SPOPS::Utility->now_between_days( { begin => '2000-10-01',
                                    end   => '2001-10-01' } );
( returns 1 )

list_process( \@existing, \@new )

Returns: hashref with three keys, each with an arrayref as the value:

keep:   items found in both \@existing and \@new
add:    items found in \@new but not \@existing
remove: items found in \@existing but not \@new

Mainly used for determining one-to-many relationship changes, but you can probably think of other applications.

COPYRIGHT

Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.

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

AUTHORS

Chris Winters <chris@cwinters.com>

See the SPOPS module for the full author list.