| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | DBIx::SQLEngine::Record::Extras - Provide extra methods | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package My::Record; | ||||||||||||||||||||||||||||
| 8 | use DBIx::SQLEngine::Record::Class '-isasubclass', 'Extras'; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | my $sqldb = DBIx::SQLEngine->new( ... ); | ||||||||||||||||||||||||||||
| 11 | My::Record->table( $sqldb->table( 'foo' ) ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | This package provides a multiply-composable collection of functionality for Record classes. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Don't use this module directly; instead, pass its name as a trait when you create a new record class. This package provides a multiply-composable collection of functionality for Record classes. It is combined with the base class and other traits by DBIx::SQLEngine::Record::Class. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | ######################################################################## | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | package DBIx::SQLEngine::Record::Extras; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | ######################################################################## | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 REFERENCE | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ######################################################################## | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub demand_table { (shift)->get_table() } | ||||||||||||||||||||||||||
|
Subroutine
demand_table: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub datasource { (shift)->get_table()->sql_engine() } | ||||||||||||||||||||||||||
|
Subroutine
datasource: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub do_sql { (shift)->get_table()->sql_engine()->do_sql( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
do_sql: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ######################################################################## | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head2 Selecting Records | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =over 4 | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item fetch_records | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | $recordset = My::Students->fetch_records( criteria => {status=>'active'} ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Fetch all matching records and return them in a RecordSet. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =item fetch_one | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | $dave = My::Students->fetch_one( criteria => { name => 'Dave' } ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Fetch a single matching record. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item fetch_id | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | $prisoner = My::Students->fetch_id( 6 ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Fetch a single record based on its primary key. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item visit_records | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | @results = My::Students->visit_records( \&mysub, criteria=> ... ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Calls the provided subroutine on each matching record as it is retrieved. Returns the accumulated results of each subroutine call (in list context). | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =item refetch_record | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | $record->refetch_record(); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Re-retrieve the values for this record from the database based on its primary key. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub new { (shift)->new_with_values( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | ######################################################################## | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub fetch_records { (shift)->fetch_select( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
fetch_records: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub visit_records { (shift)->visit_select( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
visit_records: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub fetch_sql { (shift)->fetch_select( sql => [ @_ ] ) } | ||||||||||||||||||||||||||
|
Subroutine
fetch_sql: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub fetch_id { (shift)->select_record( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
fetch_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | (shift)->fetch_select( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[0] or not defined $_[0]
MC/DC0%0/2
ref $_[0] or not defined $_[0]
ref $_[0]
not defined $_[0]
Truth table0%0/3
A or not(B)
A= ref $_[0]B= not defined $_[0]
| |||||||||||||||||||||||||||||
| 92 | ( ref $_[0] or ! defined $_[0] ) ? (where=>$_[0], order=>$_[1]) | ||||||||||||||||||||||||||||
| 93 | : @_ | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub fetch_one { | ||||||||||||||||||||||||||
|
Subroutine
fetch_one: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | 0 | my $records = $self->fetch( @_ ); | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | ( scalar @$records < 2 ) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | carp "Multiple matches for fetch_one: " . join(', ', map "'$_'", @_ ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | $records->[0]; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub refetch_record { | ||||||||||||||||||||||||||
|
Subroutine
refetch_record: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my $self = shift(); | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $db_row = $self->get_table()->select_row( $self ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | or confess; | ||||||||||||||||||||||||||||
| 110 | 0 | %$self = %$db_row; | |||||||||||||||||||||||||||
| 111 | 0 | $self->post_fetch; | |||||||||||||||||||||||||||
| 112 | 0 | $self; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | ######################################################################## | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub change { (shift)->change_values() } | ||||||||||||||||||||||||||
|
Subroutine
change: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | ######################################################################## | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub save_row { (shift)->save_record(@_) } | ||||||||||||||||||||||||||
|
Subroutine
save_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub insert_row { (shift)->insert_record( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
insert_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub update_row { (shift)->update_record( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
update_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub delete_row { (shift)->delete_record( @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
delete_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | ######################################################################## | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1 | 1; | |||||||||||||||||||||||||||