| 1 | package Audit::DBI::Event; | ||||||||||
| 2 | |||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 18 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 18 | ▶ | use Data::Validate::Type; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 18 | ▶ | use Storable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 18 | ▶ | use MIME::Base64 qw(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Audit::DBI::Event - An event as logged by the Audit::DBI module. | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | =head1 VERSION | ||||||||||
| 18 | |||||||||||
| 19 | Version 1.9.0 | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 18 | our $VERSION = '1.9.0'; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | use Audit::DBI::Event; | ||||||||||
| 29 | |||||||||||
| 30 | my $audit_event = Audit::DBI::Event->new( | ||||||||||
| 31 | data => $data, #mandatory | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | my $audit_event_id = $audit_event->get_id(); | ||||||||||
| 35 | my $information = $audit_event->get_information(); | ||||||||||
| 36 | my $diff = $audit_event->get_diff(); | ||||||||||
| 37 | my $ipv4_address = $audit_event->get_ipv4_address(); | ||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | =head1 METHODS | ||||||||||
| 41 | |||||||||||
| 42 | =head2 new() | ||||||||||
| 43 | |||||||||||
| 44 | Create a new Audit::DBI::Event object. | ||||||||||
| 45 | |||||||||||
| 46 | my $audit_event = Audit::DBI::Event->new( | ||||||||||
| 47 | data => $data, #mandatory | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | Note that you should never have to instantiate Audit::DBI::Event objects | ||||||||||
| 51 | directly. They are normally created by the Audit::DBI module. | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | sub new | ||||||||||
| 56 | 49 | ▶ | { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 57 | 49 | my ( $class, %args ) = @_; | |||||||||
| 58 | 49 | my $data = delete( $args{'data'} ); | |||||||||
| 59 | |||||||||||
| 60 | 49 | ▶ | croak 'The parameter "data" is mandatory' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | if !defined( $data ); | ||||||||||
| 62 | 48 | ▶ | croak 'The parameter "data" must be a hashref' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | if !Data::Validate::Type::is_hashref( $data ); | ||||||||||
| 64 | |||||||||||
| 65 | 47 | return bless( $data, $class ); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | =head1 ACCESSORS | ||||||||||
| 70 | |||||||||||
| 71 | =head2 get_id() | ||||||||||
| 72 | |||||||||||
| 73 | Return the audit event ID. | ||||||||||
| 74 | |||||||||||
| 75 | my $audit_event_id = $audit_event->get_id(); | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | sub get_id | ||||||||||
| 80 | 1 | ▶ | { | ||||||||
|
Subroutine
get_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 81 | 1 | my ( $self ) = @_; | |||||||||
| 82 | |||||||||||
| 83 | 1 | return $self->{'audit_event_id'}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | =head2 get_information() | ||||||||||
| 88 | |||||||||||
| 89 | Retrieve the extra information stored, if any. | ||||||||||
| 90 | |||||||||||
| 91 | my $information = $audit_event->get_information(); | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | sub get_information | ||||||||||
| 96 | 1 | ▶ | { | ||||||||
|
Subroutine
get_information: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 97 | 1 | my ( $self ) = @_; | |||||||||
| 98 | |||||||||||
| 99 | return defined( $self->{'information'} ) | ||||||||||
| 100 | 1 | ▶ | ? Storable::thaw( MIME::Base64::decode_base64( $self->{'information'} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | : undef; | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | =head2 get_diff() | ||||||||||
| 106 | |||||||||||
| 107 | Retrieve the diff information stored, if any. | ||||||||||
| 108 | |||||||||||
| 109 | my $diff = $audit_event->get_diff(); | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | sub get_diff | ||||||||||
| 114 | 2 | ▶ | { | ||||||||
|
Subroutine
get_diff: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 115 | 2 | my ( $self ) = @_; | |||||||||
| 116 | |||||||||||
| 117 | return defined( $self->{'diff'} ) | ||||||||||
| 118 | 2 | ▶ | ? Storable::thaw( MIME::Base64::decode_base64( $self->{'diff'} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | : undef; | ||||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | =head2 get_diff_string_bytes() | ||||||||||
| 124 | |||||||||||
| 125 | Return the size in bytes of all the text changes recorded inside the diff | ||||||||||
| 126 | information stored for the event. | ||||||||||
| 127 | |||||||||||
| 128 | This method can use two comparison types to calculate the size of the changes | ||||||||||
| 129 | inside a diff: | ||||||||||
| 130 | |||||||||||
| 131 | =over 4 | ||||||||||
| 132 | |||||||||||
| 133 | =item * Relative comparison (by default): | ||||||||||
| 134 | |||||||||||
| 135 | In this case, a string change from 'TestABC' to 'TestCDE' is a 0 bytes | ||||||||||
| 136 | change (since there is the same number of characters). | ||||||||||
| 137 | |||||||||||
| 138 | my $diff_bytes = $audit_event->get_diff_string_bytes(); | ||||||||||
| 139 | |||||||||||
| 140 | =item * Absolute comparison: | ||||||||||
| 141 | |||||||||||
| 142 | In this case, a string change from 'TestABC' to 'TestCDE' is a 6 bytes | ||||||||||
| 143 | change (3 characters removed, and 3 added). | ||||||||||
| 144 | |||||||||||
| 145 | my $diff_bytes = $audit_event->get_diff_string_bytes( absolute => 1 ); | ||||||||||
| 146 | |||||||||||
| 147 | Note that absolute comparison requires L<String::Diff> to be installed. | ||||||||||
| 148 | |||||||||||
| 149 | =back | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | |||||||||||
| 153 | sub get_diff_string_bytes | ||||||||||
| 154 | 1 | ▶ | { | ||||||||
|
Subroutine
get_diff_string_bytes: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 155 | 1 | my ( $self, %args ) = @_; | |||||||||
| 156 | |||||||||||
| 157 | 1 | my $diff = $self->get_diff(); | |||||||||
| 158 | 1 | ▶ | return 0 if !defined( $diff ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | 1 | return Audit::DBI::Utils::get_diff_string_bytes( | |||||||||
| 161 | $diff, | ||||||||||
| 162 | %args, | ||||||||||
| 163 | ); | ||||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | |||||||||||
| 167 | =head2 get_ipv4_address() | ||||||||||
| 168 | |||||||||||
| 169 | Return the IPv4 address associated with the audit event. | ||||||||||
| 170 | |||||||||||
| 171 | my $ipv4_address = $audit_event->get_ipv4_address(); | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | sub get_ipv4_address | ||||||||||
| 176 | 1 | ▶ | { | ||||||||
|
Subroutine
get_ipv4_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 177 | 1 | my ( $self ) = @_; | |||||||||
| 178 | |||||||||||
| 179 | 1 | return Audit::DBI::Utils::integer_to_ipv4( $self->{'ipv4_address'} ); | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | |||||||||||
| 183 | =head1 BUGS | ||||||||||
| 184 | |||||||||||
| 185 | Please report any bugs or feature requests through the web interface at | ||||||||||
| 186 | L<https://github.com/guillaumeaubert/Audit-DBI/issues/new>. | ||||||||||
| 187 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 188 | your bug as I make changes. | ||||||||||
| 189 | |||||||||||
| 190 | |||||||||||
| 191 | =head1 SUPPORT | ||||||||||
| 192 | |||||||||||
| 193 | You can find documentation for this module with the perldoc command. | ||||||||||
| 194 | |||||||||||
| 195 | perldoc Audit::DBI::Event | ||||||||||
| 196 | |||||||||||
| 197 | |||||||||||
| 198 | You can also look for information at: | ||||||||||
| 199 | |||||||||||
| 200 | =over 4 | ||||||||||
| 201 | |||||||||||
| 202 | =item * GitHub's request tracker | ||||||||||
| 203 | |||||||||||
| 204 | L<https://github.com/guillaumeaubert/Audit-DBI/issues> | ||||||||||
| 205 | |||||||||||
| 206 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 207 | |||||||||||
| 208 | L<http://annocpan.org/dist/Audit-DBI> | ||||||||||
| 209 | |||||||||||
| 210 | =item * CPAN Ratings | ||||||||||
| 211 | |||||||||||
| 212 | L<http://cpanratings.perl.org/d/Audit-DBI> | ||||||||||
| 213 | |||||||||||
| 214 | =item * MetaCPAN | ||||||||||
| 215 | |||||||||||
| 216 | L<https://metacpan.org/release/Audit-DBI> | ||||||||||
| 217 | |||||||||||
| 218 | =back | ||||||||||
| 219 | |||||||||||
| 220 | |||||||||||
| 221 | =head1 AUTHOR | ||||||||||
| 222 | |||||||||||
| 223 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||
| 224 | C<< <aubertg at cpan.org> >>. | ||||||||||
| 225 | |||||||||||
| 226 | |||||||||||
| 227 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 228 | |||||||||||
| 229 | Copyright 2010-2017 Guillaume Aubert. | ||||||||||
| 230 | |||||||||||
| 231 | This code is free software; you can redistribute it and/or modify it under the | ||||||||||
| 232 | same terms as Perl 5 itself. | ||||||||||
| 233 | |||||||||||
| 234 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||||||
| 235 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||
| 236 | PARTICULAR PURPOSE. See the LICENSE file for more details. | ||||||||||
| 237 | |||||||||||
| 238 | =cut | ||||||||||
| 239 | |||||||||||
| 240 | 18 | 1; | |||||||||