Class::DBI::Plugin::TimePiece::Oracle - Extension to Class::DBI for Oracle DATE type.


Class-DBI-Plugin-TimePiece-Oracle documentation Contained in the Class-DBI-Plugin-TimePiece-Oracle distribution.

Index


Code Index:

NAME

Top

Class::DBI::Plugin::TimePiece::Oracle - Extension to Class::DBI for Oracle DATE type.

VERSION

Top

This documentation refers to Class::DBI::Plugin::TimePiece::Oracle version 0.01

SYNOPSIS

Top

 __PACKAGE__->has_a_auto_timepiece( INS_DATE );
 __PACKAGE__->has_a_atp( UPDATE_DATE );

DESCRIPTION

Top

This module is Extensionto Class::DBI for Oracle DATE type. This module supports Oracle DATE TYPE limitedly. This module supports the following FORMAT.

 - YYYY
 - YY
 - RRRR
 - RR
 - MM
 - MON
 - MONTH
 - DD
 - HH
 - HH24
 - MI
 - SS

METHOD

Top

has_a_auto_timepiece

This method is automatic related by useing Time::Piece for Oracle date type. This method need Class::DBI::Plugin::DateFormat::Oracle's get_nls_date_format method.

 __PACKAGE__->has_a_auto_timepiece( INS_DATE );

INS_DATE colum related to Time::Piece Object.

has_a_atp

has_a_atp is has_a_auto_timepiece'a alias.

_get_nls_date_format

_get_nls_date_format converts nls_date_format into Time::Piece format.

DEPENDENCIES

Top

Carp, Time::Piece, Class::DBI::Plugin::DateFormat::Oracle

SEE ALSO

Top

Carp, Time::Piece, Class::DBI::Plugin::DateFormat::Oracle

BUGS AND LIMITATIONS

Top

There are no known bugs in this module. Please report problems to Atsushi Kobayashi (<nekokak@cpan.org>) Patches are welcome.

AUTHOR

Top

Atsushi Kobayashi, <nekokak@cpan.org>

COPYRIGHT AND LICENSE

Top


Class-DBI-Plugin-TimePiece-Oracle documentation Contained in the Class-DBI-Plugin-TimePiece-Oracle distribution.

package Class::DBI::Plugin::TimePiece::Oracle;

use strict;
use warnings;
use Carp;
use Class::DBI::Plugin::DateFormat::Oracle;

use vars '$VERSION';

$VERSION = '0.01';

# This module supports the following %FORMAT.
my %FORMAT = (
    'YYYY'  => '%Y',
    'YY'    => '%y',
    'RRRR'  => '%Y',
    'RR'    => '%y',
    'MM'    => '%m',
    'MON'   => '%b',
    'MONTH' => '%B',
    'DD'    => '%d',
    'HH'    => '%I',
    'HH24'  => '%H',
    'MI'    => '%M',
    'SS'    => '%S',
);

# This module supports the following $SEPARATOR.
my $SEPARATOR = q[\s\-\/\,\;\:];

sub import {
    my $class = shift;
    my $pkg   = caller(0);
    my $format;
    my $nsl_format;

    no strict 'refs';
    *{"$pkg\::has_a_auto_timepiece"} = sub {
        my $self   = shift;
        my $colum  = shift;
        $self->_get_nls_date_format;
        $self->has_a(
            $colum  => 'Time::Piece',
            inflate => sub { Time::Piece->strptime(shift , $format ) },
            deflate => sub { shift->strftime($format) },
        );
    };

    *{"$pkg\::has_a_atp"} = *{"$pkg\::has_a_auto_timepiece"};

    *{"$pkg\::_get_nls_date_format"} = sub {
        my $self = shift;

        if ( defined $format ) {
            return;
        }

        if ( ! defined $nsl_format ) {
            $nsl_format = $self->get_nls_date_format;
        }

        my $chk_target = $nsl_format;
        $format        = $nsl_format;

        for my $key ( reverse sort keys %FORMAT ) {
            $format     =~ s/${key}/$FORMAT{$key}/;
            $chk_target =~ s/${key}//;
        }
        $self->_croak("FORMAT PARSE ERROR!") if ( $chk_target eq q[] && $chk_target =~ /[^${SEPARATOR}]/ );
    };

    goto &Class::DBI::Plugin::DateFormat::Oracle::import;
}

1;
__END__