| 1 | use MooseX::Declare; | ||
| 2 | use DateTime; | ||
| 3 | use MooseX::Types::DateTime qw(DateTime); | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Role::Audit - utility methods for ETLp auiditing | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This role provides a wrapper around ETLp::Config. It's purpose | ||
| 12 | is top provide simple access to the configuration setting | ||
| 13 | |||
| 14 | =head1 METHODS | ||
| 15 | |||
| 16 | =head2 get_driver | ||
| 17 | |||
| 18 | Return the name of the DBD driver for the audit connection | ||
| 19 | |||
| 20 | =head2 now | ||
| 21 | |||
| 22 | Return the current date and time as a DateTime object for the local time_zone' | ||
| 23 | |||
| 24 | =head2 db_time | ||
| 25 | |||
| 26 | Return the supplied DateTime object as a DB-specific date and time string | ||
| 27 | |||
| 28 | =head2 db_now | ||
| 29 | |||
| 30 | Return the current date and time as a DB-specific string | ||
| 31 | |||
| 32 | =head2 get_status_id | ||
| 33 | |||
| 34 | Given a status name, return the primary key | ||
| 35 | |||
| 36 | =head2 get_phase_id | ||
| 37 | |||
| 38 | Given a phase name, return the primay key | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | |||
| 43 | role ETLp::Role::Audit { | ||
| 44 | use DBI::Const::GetInfoType; | ||
| 45 | use ETLp::Types; | ||
| 46 | |||
| 47 | method get_driver { | ||
| 48 | return $self->schema->storage->dbh->get_info($GetInfoType{SQL_DBMS_NAME}) | ||
| 49 | } | ||
| 50 | |||
| 51 | method now { | ||
| 52 | my $dt = DateTime->now(time_zone => 'local'); | ||
| 53 | return $dt; | ||
| 54 | } | ||
| 55 | |||
| 56 | method db_time(DateTime $date) { | ||
| 57 | return $self->schema->storage->datetime_parser->format_datetime($date); | ||
| 58 | } | ||
| 59 | |||
| 60 | method db_now { | ||
| 61 | return $self->db_time($self->now); | ||
| 62 | } | ||
| 63 | |||
| 64 | method get_status_id (Str $status_name) { | ||
| 65 | my $status = $self->EtlpStatus->search({status_name => $status_name}); | ||
| 66 | return $status->first->status_id; | ||
| 67 | } | ||
| 68 | |||
| 69 | method get_phase_id (Str $phase_name) { | ||
| 70 | my $phase = $self->EtlpPhase->search({phase_name => $phase_name}); | ||
| 71 | return $phase->first->phase_id; | ||
| 72 | } | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | =head1 LICENSE AND COPYRIGHT | ||
| 77 | |||
| 78 | Copyright 2010 Redbone Systems Ltd | ||
| 79 | |||
| 80 | This program is free software; you can redistribute it and/or modify it | ||
| 81 | under the terms of either: the GNU General Public License as published | ||
| 82 | by the Free Software Foundation; or the Artistic License. | ||
| 83 | |||
| 84 | The terms are in the LICENSE file that accompanies this application | ||
| 85 | |||
| 86 | =cut |