| 1 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Data::Conveyor::Storage::DBI::Core::Setup; | ||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | $Data::Conveyor::Storage::DBI::Core::Setup::VERSION = '1.103130'; | |||||||||
| 8 | } | ||||||||||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||||||||||
| 10 | |||||||||||
| 11 | # Utility storage methods encapsulating statements that all or most | ||||||||||
| 12 | # applications based on Data-Conveyor are going to need. They presume a | ||||||||||
| 13 | # certain database layout, so if you use these conventions, these methods will | ||||||||||
| 14 | # work for you. If not, they won't. | ||||||||||
| 15 | 1 | ▶ | use DBI ':sql_types'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub add_lookup_items { | ||||||||
|
Subroutine
add_lookup_items: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 18 | 0 | my ($self, $table_name, $table_prefix, @items) = @_; | |||||||||
| 19 | 0 | $self->log->info('add_lookup_items [%s]', $table_name); | |||||||||
| 20 | |||||||||||
| 21 | # normalize the table name | ||||||||||
| 22 | 0 | ▶ | $table_name = '<P>_' . $table_name unless $table_name =~ /^<P>_/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | # find the new items by removing the existing ones from the list given to | ||||||||||
| 25 | # us. | ||||||||||
| 26 | 0 | my %insert = map { $_ => 1 } @items; | |||||||||
| 27 | 0 | my $item; | |||||||||
| 28 | 0 | my $sth = $self->prepare(" | |||||||||
| 29 | SELECT ${table_prefix}_code FROM $table_name | ||||||||||
| 30 | "); | ||||||||||
| 31 | 0 | $sth->execute; | |||||||||
| 32 | 0 | $sth->bind_columns(\$item); | |||||||||
| 33 | 0 | ▶ | while ($sth->fetch) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $self->log->debug('existing [%s] lookup item [%s]', $table_name, $item); | |||||||||
| 35 | 0 | delete $insert{$item}; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | $sth->finish; | |||||||||
| 38 | 0 | $sth = $self->prepare(" | |||||||||
| 39 | INSERT INTO $table_name ( | ||||||||||
| 40 | ${table_prefix}_id, | ||||||||||
| 41 | ${table_prefix}_code, | ||||||||||
| 42 | ${table_prefix}_create_user, | ||||||||||
| 43 | ${table_prefix}_create_date | ||||||||||
| 44 | ) VALUES ( | ||||||||||
| 45 | <NEXTVAL>(<P>_id_seq), | ||||||||||
| 46 | :item, | ||||||||||
| 47 | <USER>, | ||||||||||
| 48 | <NOW> | ||||||||||
| 49 | ) | ||||||||||
| 50 | "); | ||||||||||
| 51 | 0 | for my $new_item (sort keys %insert) { | |||||||||
| 52 | 0 | $self->log->info('inserting [%s] lookup item [%s]', | |||||||||
| 53 | $table_name, $new_item); | ||||||||||
| 54 | 0 | $sth->bind_param(':item', $new_item, SQL_VARCHAR); | |||||||||
| 55 | 0 | $sth->execute; | |||||||||
| 56 | } | ||||||||||
| 57 | 0 | $sth->finish; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub add_ticket_types { | ||||||||
|
Subroutine
add_ticket_types: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 61 | 0 | my ($self, @ticket_types) = @_; | |||||||||
| 62 | 0 | $self->add_lookup_items('request_types', 'ret', @ticket_types); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub add_origins { | ||||||||
|
Subroutine
add_origins: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | 0 | my ($self, @origins) = @_; | |||||||||
| 67 | 0 | $self->add_lookup_items('origins', 'ori', @origins); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub prime { | ||||||||
|
Subroutine
prime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | 0 | my $self = shift; | |||||||||
| 72 | 0 | $self->add_ticket_types($self->delegate->TT); | |||||||||
| 73 | 0 | $self->add_origins($self->delegate->OR); | |||||||||
| 74 | } | ||||||||||
| 75 | 1 | 1; | |||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||