AuditAny/DataPoint.pm

filter: Statementstmt 77.4% 24 / 31 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 1 / 1 totaltotal 71.7% 33 / 46 CC 3 SCAR 7.2
CC
3
Cov
71%
get_value
6.0
__ANON__
2.1
__ANON__
1.3
CRAP 2.1
« AuditAny/AuditContext/Column.pm ↑ Summary AuditAny/Role/Schema.pm »
1 package DBIx::Class::AuditAny::DataPoint;
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: Object class for AuditAny datapoint configs
6  
7 =head1 NAME
8  
9 DBIx::Class::AuditAny::DataPoint - Object class for AuditAny datapoint configs
10  
11 =head1 DESCRIPTION
12  
13 This class defines the *config* of a datapoint, not the *value*
14 of the datapoint. It is used to get the value, but the value itself
15 is not stored within this object. Datapoint values are stored within
16 the Context objects whose life-cycle is limited to individual tracked
17 database operations, and -only- after being called from the Collector.
18  
19 Datapoints are just only optional sugar for abstracting and simplifying
20 useful collection of data as key/values. It just provides a nice way to
21 organize data that has already been retrieved. They are *never* automatically
22 calculated; only made available to the Collector. Note that this means
23 datapoint values are only retrieved -after- the database operation is completed,
24 and thus only have access to the data that has already been collected (or is
25 otherwise available to) the given Context object. I thought long and hard
26 about this design... At one point I was going to expand the paradigm to
27 provide 'pre' vs 'post' hooks, but ultimately decided that this would be
28 overkill and over-complicate things. To accomplish custom collection of
29 data at the 'pre' stage (i.e. *before* the tracked database operation is
30 executed) a custom Context object should be written. This could then of
31 course be paired with a custom datapoint config to access this extra data
32 in the custom Context, but that is incidental (i.e. just organizing the data
33 after the actual work to collect it)
34  
35 =head1 ATTRIBUTES
36  
37 =cut
38  
39 14 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 14 ▶use MooX::Types::MooseLike::Base 0.19 qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 =head2 AuditObj
43  
44 Required. Reference to the Auditor object (L<DBIx::Class::AuditAny> instance).
45  
46 =cut
47 14 has 'AuditObj', is => 'ro', isa => InstanceOf['DBIx::Class::AuditAny'], required => 1;
48  
49 =head2 name
50  
51 The unique name of the DataPoint (i.e. 'key')
52  
53 =cut
54 178 ▶has 'name', is => 'ro', required => 1, isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
55 178 ▶ $_[0] =~ /^[a-z0-9\_\-]+$/ or die "'$_[0]' is invalid - " .
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^[a-z0-9\_\-]+$/ or die "'$_[0]' is invalid - " . 'only lowercase letters, numbers, underscore(_) and dash(-) allowed' 178 0 178
56 "only lowercase letters, numbers, underscore(_) and dash(-) allowed";
57 14 };
58  
59 =head2 context
60  
61 The name of the -context- which determines at what point the value
62 can be computed and collected, and into which Context -object- it
63 will be cached (although, since Context objects overlay in a hierarchy,
64 lower-level contexts can automatically access the datapoint values of the
65 higher-level contexts (i.e. 'set' datapoints are implied in 'change'
66 context but not 'column' datapoints. This is just standard belongs_to vs
67 has_many logic based on the way contexts are interrelated, regardless of
68 how or if they are actually stored)
69  
70 =cut
71 14 has 'context', is => 'ro', required => 1,
72 isa => Enum[qw(base source set change column)];
73  
74 =head2 method
75  
76 method is what is called to get the value of the datapoint. It is a
77 CodeRef and is supplied the Context object (ChangeSet, Change, Column, etc)
78 as the first argument. As a convenience, it can also be a Str in which
79 case it is an existing method name within the Context object
80  
81 =cut
82 14 has 'method', is => 'ro', isa => AnyOf[CodeRef,Str], required => 1;
83  
84 =head2 user_defined
85  
86 Informational flag set to identify if this datapoint has been
87 defined custom, on-the-fly, or is a built-in
88  
89 =cut
90 174 ▶has 'user_defined', is => 'ro', isa => Bool, default => sub{0};
Subroutine __ANON__: called CC=1 SCAR=0.0
91  
92 =head2 original_name
93  
94 Optional extra attr to keep track of a separate 'original' name. Auto
95 set when 'rename_datapoints' are specified (see top DBIx::Class::AuditAny class)
96  
97 =cut
98 has 'original_name', is => 'ro', isa => Str, lazy => 1,
99 118 ▶ default => sub { (shift)->name };
Subroutine __ANON__: called CC=1 SCAR=0.0
100  
101 =head2 column_info
102  
103 defines the schema needed to store this datapoint within
104 a DBIC Result/table. Only used in collectors like Collector::AutoDBIC
105  
106 =cut
107 has 'column_info', is => 'ro', isa => HashRef, lazy => 1,
108 0 ▶ default => sub { my $self = shift; $self->_get_column_info->($self) };
Subroutine __ANON__: not called CC=1 SCAR=2.6
109
110 has '_get_column_info', is => 'ro', isa => CodeRef, lazy => 1,
111 0 ▶ default => sub {{ data_type => "varchar" }};
Subroutine __ANON__: not called CC=1 SCAR=1.2
112 # --
113  
114 =head1 METHODS
115  
116 =head2 get_value
117  
118 Returns the value of the datapoint via the C<'method'> function/CodeRef
119  
120 =cut
121 0 ▶sub get_value {
Subroutine get_value: not called CC=2 SCAR=17.9
Pod documented
122 0 my $self = shift;
123 0 my $Context = shift;
124 0 my $method = $self->method;
125 0 ▶ return ref($method) ? $method->($self,$Context,@_) : $Context->$method(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $method ? : 0 0 0
126 }
127  
128 14 1;
129  
130 __END__
« AuditAny/AuditContext/Column.pm ↑ Summary AuditAny/Role/Schema.pm »