File Coverage

blib/lib/DBIx/Class/AuditAny/AuditContext/Source.pm
Criterion Covered Total %
statement 28 29 96.5
branch 4 6 66.6
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package DBIx::Class::AuditAny::AuditContext::Source;
2 13     13   6093 use strict;
  13         24  
  13         342  
3 13     13   46 use warnings;
  13         19  
  13         291  
4              
5             # ABSTRACT: Default 'Source' context object class for DBIx::Class::AuditAny
6              
7 13     13   47 use Moo;
  13         14  
  13         61  
8 13     13   15561 use MooX::Types::MooseLike::Base qw(:all);
  13         21  
  13         8489  
9             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             has 'ResultSource', is => 'ro', required => 1;
37             has 'source', is => 'ro', lazy => 1, default => sub { (shift)->ResultSource->source_name };
38             has 'class', is => 'ro', lazy => 1, default => sub { $_[0]->SchemaObj->class($_[0]->source) };
39             has 'from_name', is => 'ro', lazy => 1, default => sub { (shift)->ResultSource->from };
40             has 'table_name', is => 'ro', lazy => 1, default => sub { (shift)->class->table };
41              
42 49     49 1 215 sub primary_columns { return (shift)->ResultSource->primary_columns }
43              
44 0     0   0 sub _build_tiedContexts { [] }
45             sub _build_local_datapoint_data {
46 24     24   148 my $self = shift;
47 24         120 return { map { $_->name => $_->get_value($self) } $self->get_context_datapoints('source') };
  29         323  
48             }
49              
50             has 'pri_key_column', is => 'ro', isa => Maybe[Str], lazy => 1, default => sub {
51             my $self = shift;
52             my @cols = $self->primary_columns;
53             return undef unless (scalar(@cols) > 0);
54             my $sep = $self->primary_key_separator;
55             return join($sep,@cols);
56             };
57              
58             has 'pri_key_count', is => 'ro', isa => Int, lazy => 1, default => sub {
59             my $self = shift;
60             return scalar($self->primary_columns);
61             };
62              
63             sub get_pri_key_value {
64 145     145 1 148 my $self = shift;
65 145         122 my $Row = shift;
66 145         2068 my $num = $self->pri_key_count;
67 145 50       1936 return undef unless ($num > 0);
68 145 100       2035 return $self->_ambig_get_column($Row,$self->pri_key_column) if ($num == 1);
69 3         9 my $sep = $self->primary_key_separator;
70 3         10 return join($sep, map { $self->_ambig_get_column($Row,$_) } $self->primary_columns );
  6         19  
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             sub _ambig_get_column {
76 148     148   1688 my $self = shift;
77 148         123 my $row = shift;
78 148         146 my $column = shift;
79 148 50       2238 return ref($row) eq 'HASH' ? $row->{$column} : $row->get_column($column);
80             }
81              
82             1;
83              
84             __END__
85              
86             =head1 SEE ALSO
87              
88             =over
89              
90             =item *
91              
92             L<DBIx::Class::AuditAny>
93              
94             =item *
95              
96             L<DBIx::Class>
97              
98             =back
99              
100             =head1 SUPPORT
101            
102             IRC:
103            
104             Join #rapidapp on irc.perl.org.
105              
106             =head1 AUTHOR
107              
108             Henry Van Styn <vanstyn@cpan.org>
109              
110             =head1 COPYRIGHT AND LICENSE
111              
112             This software is copyright (c) 2012-2015 by IntelliTree Solutions llc.
113              
114             This is free software; you can redistribute it and/or modify it under
115             the same terms as the Perl 5 programming language system itself.
116              
117             =cut