AuditAny/AuditContext/ChangeSet.pm

filter: Statementstmt 43.4% 23 / 53 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.3% 5 / 19 Podpod 83.3% 5 / 6 totaltotal 38.3% 33 / 86 CC 6 SCAR 20.5
CC
6
Cov
38%
add_changes
30.0
finish
6.0
_build_tiedContexts
2.0
CRAP 7.7
« AuditAny/Collector/DBIC.pm ↑ Summary AuditAny/AuditContext/Source.pm »
1 package DBIx::Class::AuditAny::AuditContext::ChangeSet;
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 'ChangeSet' 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::ChangeSet - Default 'ChangeSet' context object
14 class for DBIx::Class::AuditAny
15  
16 =head1 DESCRIPTION
17  
18 This object class represents a "set" of changes grouped together, typically all applied within
19 the scope of a single transaction. The changes can span across multiple individual changes,
20 which can also represent changes to multiple different columns.
21  
22 This class is used internally and should not be used directly.
23  
24 =cut
25  
26 14 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 0 ▶sub _build_tiedContexts { [] }
Subroutine _build_tiedContexts: not called CC=1 SCAR=6.9
29 0 ▶sub _build_local_datapoint_data {
Subroutine _build_local_datapoint_data: not called CC=1 SCAR=6.9
30 0 my $self = shift;
31 0 return { map { $_->name => $_->get_value($self) } $self->get_context_datapoints('set') };
32 }
33  
34 =head1 ATTRIBUTES
35  
36 Docs regarding the API/purpose of the attributes and methods in this class still TBD...
37  
38 =head2 changes
39  
40 =head2 finished
41  
42 =head2 changeset_ts
43  
44 =head2 start_timeofday
45  
46 =head2 changeset_finish_ts
47  
48 =head2 changeset_elapsed
49  
50 =cut
51  
52 0 ▶has 'changes', is => 'ro', isa => ArrayRef, default => sub {[]};
Subroutine __ANON__: not called CC=1 SCAR=1.2
53 0 ▶has 'finished', is => 'rw', isa => Bool, default => sub{0}, init_arg => undef;
Subroutine __ANON__: not called CC=1 SCAR=1.2
54  
55 0 ▶has 'changeset_ts', is => 'ro', isa => InstanceOf['DateTime'], lazy => 1, default => sub { (shift)->get_dt };
Subroutine __ANON__: not called CC=1 SCAR=1.2
56 0 ▶has 'start_timeofday', is => 'ro', default => sub { [gettimeofday] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
57  
58 0 ▶has 'changeset_finish_ts', is => 'rw', isa => Maybe[InstanceOf['DateTime']], default => sub{undef};
Subroutine __ANON__: not called CC=1 SCAR=1.2
59 0 ▶has 'changeset_elapsed', is => 'rw', default => sub{undef};
Subroutine __ANON__: not called CC=1 SCAR=1.2
60  
61 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $self = shift;
63
64 # Init
65 0 $self->changeset_ts;
66 }
67  
68 =head1 METHODS
69  
70 =head2 all_changes
71  
72 =head2 count_changes
73  
74 =head2 all_column_changes
75  
76 =head2 add_changes
77  
78 =head2 finish
79  
80 =cut
81  
82 0 ▶sub all_changes { @{(shift)->changes} }
Subroutine all_changes: not called CC=1 SCAR=6.9
Pod documented
83 0 ▶sub count_changes { scalar(@{(shift)->changes}) }
Subroutine count_changes: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub all_column_changes { map { $_->all_column_changes } (shift)->all_changes }
Subroutine all_column_changes: not called CC=1 SCAR=6.9
Pod documented
85  
86 0 ▶sub add_changes {
Subroutine add_changes: not called CC=5 SCAR=34.0
Pod documented
87 0 my ($self, @ChangeContexts) = @_;
88
89 0 ▶ die "Cannot add_changes to finished ChangeSet!" if ($self->finished);
Branch: 1 branch
BranchTrueFalseTotal
if $self->finished 0 0 0
90
91 0 foreach my $ChangeContext (@ChangeContexts) {
92
93 # New: It is now possible that there is no attached ChangeSet yet, since ChangeContext
94 # is now created -before- the action operation is executed, and thus before
95 # a changeset is automatically started (we do this so we don't have to worry
96 # about exceptions). But by the time ->record() is called, we know the operation
97 # has succeeded, and we also know that a new changeset has been created if the
98 # operation was not already wrapped in a transaction. Se we just set it now:
99 0 ▶ $ChangeContext->ChangeSetContext($self) unless ($ChangeContext->ChangeSetContext);
Branch: 1 branch
BranchTrueFalseTotal
unless $ChangeContext->ChangeSetContext 0 0 0
100
101 # Extra check for good measure:
102 0 ▶ die "Attempted to add changes attached to a different changeset!"
Branch: 1 branch
BranchTrueFalseTotal
unless $self == $ChangeContext->ChangeSetContext 0 0 0
103 unless ($self == $ChangeContext->ChangeSetContext);
104
105 0 push @{$self->changes}, $ChangeContext;
106 }
107 }
108  
109  
110 0 ▶sub finish {
Subroutine finish: not called CC=2 SCAR=17.9
Pod documented
111 0 my $self = shift;
112 0 ▶ return if ($self->finished);
Branch: 1 branch
BranchTrueFalseTotal
if $self->finished 0 0 0
113
114 0 $self->changeset_finish_ts($self->get_dt);
115 0 $self->changeset_elapsed(sprintf('%.8g',tv_interval($self->start_timeofday)));
116
117 0 return $self->finished(1);
118 }
119  
120 14 1;
121  
122 __END__
« AuditAny/Collector/DBIC.pm ↑ Summary AuditAny/AuditContext/Source.pm »