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 14     14   7695 use strict;
  14         43  
  14         463  
3 14     14   85 use warnings;
  14         49  
  14         438  
4              
5             # ABSTRACT: Default 'Source' context object class for DBIx::Class::AuditAny
6              
7 14     14   87 use Moo;
  14         37  
  14         82  
8 14     14   22297 use MooX::Types::MooseLike::Base qw(:all);
  14         43  
  14         12586  
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 55     55 1 300 sub primary_columns { return (shift)->ResultSource->primary_columns }
43              
44 0     0   0 sub _build_tiedContexts { [] }
45             sub _build_local_datapoint_data {
46 27     27   361 my $self = shift;
47 27         274 return { map { $_->name => $_->get_value($self) } $self->get_context_datapoints('source') };
  32         349  
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 149     149 1 284 my $self = shift;
65 149         275 my $Row = shift;
66 149         2605 my $num = $self->pri_key_count;
67 149 50       3091 return undef unless ($num > 0);
68 149 100       2728 return $self->_ambig_get_column($Row,$self->pri_key_column) if ($num == 1);
69 3         13 my $sep = $self->primary_key_separator;
70 3         14 return join($sep, map { $self->_ambig_get_column($Row,$_) } $self->primary_columns );
  6         31  
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 152     152   2997 my $self = shift;
77 152         268 my $row = shift;
78 152         254 my $column = shift;
79 152 50       2907 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