| 1 | package DBIx::Class::AuditAny::AuditContext::Source; | ||||||||||
| 2 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | # ABSTRACT: Default 'Source' context object class for DBIx::Class::AuditAny | ||||||||||
| 6 | |||||||||||
| 7 | 14 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 14 | ▶ | use MooX::Types::MooseLike::Base qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 14 | extends 'DBIx::Class::AuditAny::AuditContext'; | |||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | DBIx::Class::AuditAny::AuditContext::Source - Default 'Source' context object | ||||||||||
| 14 | class for DBIx::Class::AuditAny | ||||||||||
| 15 | |||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||
| 17 | |||||||||||
| 18 | This object class represents a change to a source itself, such as its name | ||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | =head1 ATTRIBUTES | ||||||||||
| 22 | |||||||||||
| 23 | Docs regarding the API/purpose of the attributes and methods in this class still TBD... | ||||||||||
| 24 | |||||||||||
| 25 | =head2 ResultSource | ||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 primary_columns | ||||||||||
| 30 | |||||||||||
| 31 | =head2 get_pri_key_value | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | 14 | has 'ResultSource', is => 'ro', required => 1; | |||||||||
| 37 | 21 | ▶ | has 'source', is => 'ro', lazy => 1, default => sub { (shift)->ResultSource->source_name }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 0 | ▶ | has 'class', is => 'ro', lazy => 1, default => sub { $_[0]->SchemaObj->class($_[0]->source) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 39 | 0 | ▶ | has 'from_name', is => 'ro', lazy => 1, default => sub { (shift)->ResultSource->from }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 40 | 0 | ▶ | has 'table_name', is => 'ro', lazy => 1, default => sub { (shift)->class->table }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub primary_columns { return (shift)->ResultSource->primary_columns } | ||||||||
|
Subroutine
primary_columns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _build_tiedContexts { [] } | ||||||||
|
Subroutine
_build_tiedContexts: not called CC=1 SCAR=6.9
| |||||||||||
| 45 | 0 | ▶ | sub _build_local_datapoint_data { | ||||||||
|
Subroutine
_build_local_datapoint_data: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | 0 | my $self = shift; | |||||||||
| 47 | 0 | return { map { $_->name => $_->get_value($self) } $self->get_context_datapoints('source') }; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | has 'pri_key_column', is => 'ro', isa => Maybe[Str], lazy => 1, default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 51 | 0 | my $self = shift; | |||||||||
| 52 | 0 | my @cols = $self->primary_columns; | |||||||||
| 53 | 0 | ▶ | return undef unless (scalar(@cols) > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | my $sep = $self->primary_key_separator; | |||||||||
| 55 | 0 | return join($sep,@cols); | |||||||||
| 56 | 14 | }; | |||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | has 'pri_key_count', is => 'ro', isa => Int, lazy => 1, default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 59 | 0 | my $self = shift; | |||||||||
| 60 | 0 | return scalar($self->primary_columns); | |||||||||
| 61 | 14 | }; | |||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub get_pri_key_value { | ||||||||
|
Subroutine
get_pri_key_value: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 64 | 0 | my $self = shift; | |||||||||
| 65 | 0 | my $Row = shift; | |||||||||
| 66 | 0 | my $num = $self->pri_key_count; | |||||||||
| 67 | 0 | ▶ | return undef unless ($num > 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | return $self->_ambig_get_column($Row,$self->pri_key_column) if ($num == 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | my $sep = $self->primary_key_separator; | |||||||||
| 70 | 0 | return join($sep, map { $self->_ambig_get_column($Row,$_) } $self->primary_columns ); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | # added as a bridge to be able to "get_column" with either a Row object | ||||||||||
| 74 | # or a simple HashRef via the same syntax (in get_pri_key_value above): | ||||||||||
| 75 | 0 | ▶ | sub _ambig_get_column { | ||||||||
|
Subroutine
_ambig_get_column: not called CC=2 SCAR=17.9
| |||||||||||
| 76 | 0 | my $self = shift; | |||||||||
| 77 | 0 | my $row = shift; | |||||||||
| 78 | 0 | my $column = shift; | |||||||||
| 79 | 0 | ▶ | return ref($row) eq 'HASH' ? $row->{$column} : $row->get_column($column); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 14 | 1; | |||||||||
| 83 | |||||||||||
| 84 | __END__ | ||||||||||