| 1 | package DBIx::Class::Schema::AuditLog; | ||||||||||||||||||||||||||||
| 2 | 12 | $DBIx::Class::Schema::AuditLog::VERSION = '0.6.2'; | |||||||||||||||||||||||||||
| 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 | sub connection { | ||||||||||||||||||||||||||||
| 18 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
connection: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | sub txn_do { | ||||||||||||||||||||||||||||
| 42 | 29 | ▶ | my ( $self, $user_code, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
txn_do: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | $code = sub { | ||||||||||||||||||||||||||||
| 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]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.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 | sub audited_sources{ | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
audited_sources: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | grep { $self->class($_)->isa("DBIx::Class::AuditLog") } | |||||||||||||||||||||||||||
| 82 | $self->sources; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub audited_source { | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $source = shift->source(@_); | ||||||||||||||||||||||||||
|
Subroutine
audited_source: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | sub find_or_create_audit_log_schema_template { | ||||||||||||||||||||||||||||
| 94 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
find_or_create_audit_log_schema_template: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =pod | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 NAME | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | DBIx::Class::Schema::AuditLog | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 VERSION | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | version 0.6.2 | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 DBIx::Class OVERRIDDEN METHODS | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 connection | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Overrides the DBIx::Class connection method to create an AuditLog schema. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head2 txn_do | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | Wraps the DBIx::Class txn_do method with a new changeset whenever required. | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head1 HELPER METHODS | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head2 audited_sources | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | returns the list of sourcenames which have DBIx::Class::AuditLog loaded | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head2 audited_source | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =over | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item Arguments: $source_name | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =back | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Like L<DBIx::Class::Schema/source>, but returns 0 if the resulting source does not have | ||||||||||||||||||||||||||||
| 167 | AuditLog loaded | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head2 find_or_create_audit_log_schema_template | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Finds or creates a new schema object using the AuditLog tables. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Mark Jubenville <ioncache@cpan.org> | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | This software is copyright (c) 2012 by Mark Jubenville. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 182 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||