| 1 | package DBIx::Class::Schema::AuditLog; | ||||||||||||||||||||||||||||
| 2 | 12 | $DBIx::Class::Schema::AuditLog::VERSION = '0.6.4'; | |||||||||||||||||||||||||||
| 3 | 12 | ▶ | use base qw/DBIx::Class::Schema/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Class::C3::Componentised (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use DBIx::Class::Schema::AuditLog::Structure; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 12 | __PACKAGE__->mk_classdata('audit_log_connection'); | |||||||||||||||||||||||||||
| 13 | 12 | __PACKAGE__->mk_classdata('audit_log_schema'); | |||||||||||||||||||||||||||
| 14 | 12 | __PACKAGE__->mk_classdata('audit_log_schema_template'); | |||||||||||||||||||||||||||
| 15 | 12 | __PACKAGE__->mk_classdata('audit_log_storage_type'); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | ▶ | sub connection { | ||||||||||||||||||||||||||
|
Subroutine
connection: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 12 | my $schema = $self->next::method(@_); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 12 | ▶ | my $audit_log_schema = ( ref $self || $self ) | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 23 | ->find_or_create_audit_log_schema_template->clone; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 12 | ▶ | if ( $self->audit_log_connection ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $audit_log_schema->storage_type( $self->audit_log_storage_type ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | if $self->audit_log_storage_type; | ||||||||||||||||||||||||||||
| 28 | 0 | $audit_log_schema->connection( @{ $self->audit_log_connection } ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||
| 31 | 12 | $audit_log_schema->storage( $schema->storage ); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 12 | $self->audit_log_schema($audit_log_schema); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | $self->audit_log_schema->storage->disconnect(); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 12 | return $schema; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 29 | ▶ | sub txn_do { | ||||||||||||||||||||||||||
|
Subroutine
txn_do: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 29 | my ( $self, $user_code, @args ) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 29 | my $audit_log_schema = $self->audit_log_schema; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 29 | my $code = $user_code; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 29 | my $changeset_data = $args[0]; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 29 | my $current_changeset = $audit_log_schema->_current_changeset; | |||||||||||||||||||||||||||
| 51 | 29 | ▶ | if ( !$current_changeset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 29 | my $current_changeset_ref | |||||||||||||||||||||||||||
| 53 | = $audit_log_schema->_current_changeset_container; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 29 | ▶ | unless ($current_changeset_ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 11 | $current_changeset_ref = {}; | |||||||||||||||||||||||||||
| 57 | 11 | $audit_log_schema->_current_changeset_container( | |||||||||||||||||||||||||||
| 58 | $current_changeset_ref); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 29 | ▶ | $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | # creates local variables in the transaction scope to store | ||||||||||||||||||||||||||||
| 63 | # the changset args, and the changeset id | ||||||||||||||||||||||||||||
| 64 | 29 | local $current_changeset_ref->{args} = $args[0]; | |||||||||||||||||||||||||||
| 65 | 29 | local $current_changeset_ref->{changeset} = ''; | |||||||||||||||||||||||||||
| 66 | 29 | $user_code->(@_); | |||||||||||||||||||||||||||
| 67 | 29 | }; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 29 | ▶ | if ( $audit_log_schema->storage != $self->storage ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | my $inner_code = $code; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $code = sub { $audit_log_schema->txn_do( $inner_code, @_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 29 | return $self->next::method( $code, @args ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub audited_sources{ | ||||||||||||||||||||||||||
|
Subroutine
audited_sources: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 0 | grep { $self->class($_)->isa("DBIx::Class::AuditLog") } | |||||||||||||||||||||||||||
| 82 | $self->sources; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub audited_source { | ||||||||||||||||||||||||||
|
Subroutine
audited_source: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $source = shift->source(@_); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $source if $source && $source->isa("DBIx::Class::AuditLog"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$source and $source->isa("DBIx::Class::AuditLog")
MC/DC0%0/2
$source and $source->isa("DBIx::Class::AuditLog")
$source
$source->isa("DBIx::Class::AuditLog")
Truth table0%0/3
A and B
A= $sourceB= $source->isa("DBIx::Class::AuditLog")
| |||||||||||||||||||||||||||||
| 90 | 0 | return 0; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 12 | ▶ | sub find_or_create_audit_log_schema_template { | ||||||||||||||||||||||||||
|
Subroutine
find_or_create_audit_log_schema_template: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 12 | my $schema = $self->audit_log_schema_template; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 12 | ▶ | return $schema if $schema; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 12 | ▶ | my $c = blessed($self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($self) || $self
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self)
$self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 12 | my $class = "${c}::_AUDITLOG"; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 12 | Class::C3::Componentised->inject_base( $class, | |||||||||||||||||||||||||||
| 105 | 'DBIx::Class::Schema::AuditLog::Structure' ); | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 12 | $schema = $self->audit_log_schema_template( | |||||||||||||||||||||||||||
| 108 | $class->compose_namespace( $c . '::AuditLog' ) ); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 12 | my $prefix = 'AuditLog'; | |||||||||||||||||||||||||||
| 111 | 12 | foreach my $audit_log_table ( | |||||||||||||||||||||||||||
| 112 | qw< Action Change Changeset Field AuditedTable User View >) | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 84 | my $class = blessed($schema) . "::$audit_log_table"; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 84 | Class::C3::Componentised->inject_base( $class, | |||||||||||||||||||||||||||
| 117 | "DBIx::Class::Schema::AuditLog::Structure::$audit_log_table" ); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 84 | $schema->register_class( $prefix . $audit_log_table, $class ); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 12 | return $schema; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 12 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||