| 1 | package Log::Saftpresse::Plugin::Role::Tracking; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||
| 6 | # ABSTRACT: role for plugins to implement transaction tracking | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Log::Saftpresse::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use UUID; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | sub set_tracking_id { | ||||||||||
| 12 | 0 | ▶ | my ( $self, $by, $stash, $notes, $key ) = @_; | ||||||||
|
Subroutine
set_tracking_id: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 13 | 0 | ▶ | if( ! defined $key ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | $key = $stash->{$by}; | |||||||||
| 15 | } | ||||||||||
| 16 | 0 | ▶ | if( ! defined $key ) { return; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | my $id = $stash->{'tracking_id'}; | |||||||||
| 18 | 0 | ▶ | if( ! defined $id ) { return; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | $notes->set("tracking-$by-$key", $id); | |||||||||
| 21 | 0 | $log->debug("assigned existing tracking_id for $by-$key"); | |||||||||
| 22 | |||||||||||
| 23 | 0 | return; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | sub get_tracking_id { | ||||||||||
| 27 | 0 | ▶ | my ( $self, $by, $stash, $notes, $key ) = @_; | ||||||||
|
Subroutine
get_tracking_id: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 28 | 0 | ▶ | if( ! defined $key ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $key = $stash->{$by}; | |||||||||
| 30 | } | ||||||||||
| 31 | 0 | ▶ | if( ! defined $key ) { return; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | my $id = $notes->get("tracking-$by-$key"); | |||||||||
| 34 | 0 | ▶ | if( defined $id ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | $stash->{'tracking_id'} = $id; | |||||||||
| 36 | 0 | $log->debug("found existing tracking_id found for $by-$key"); | |||||||||
| 37 | } else { | ||||||||||
| 38 | 0 | $log->debug("no tracking_id found for $by-$key"); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub clear_tracking_id { | ||||||||||
| 45 | 0 | ▶ | my ( $self, $by, $stash, $notes ) = @_; | ||||||||
|
Subroutine
clear_tracking_id: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 46 | 0 | my $key = $stash->{$by}; | |||||||||
| 47 | 0 | ▶ | if( ! defined $key ) { return; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | $notes->remove("tracking-$by-$key"); | |||||||||
| 50 | 0 | $log->debug("cleared tracking_id for $by-$key"); | |||||||||
| 51 | 0 | return; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub new_tracking_id { | ||||||||||
| 55 | 0 | ▶ | my ( $self, $stash, $notes ) = @_; | ||||||||
|
Subroutine
new_tracking_id: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | if( defined $stash->{'pid'} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | # rt.cpan.org #114390 | ||||||||||
| 59 | # requires UUID >=0.06: | ||||||||||
| 60 | # my $id = UUID::uuid; | ||||||||||
| 61 | # this will work with UUID < 0.06: | ||||||||||
| 62 | 0 | my ( $uuid, $id ); | |||||||||
| 63 | 0 | UUID::generate( $uuid ); UUID::unparse( $uuid, $id ); | |||||||||
| 64 | |||||||||||
| 65 | 0 | $stash->{'tracking_id'} = $id; | |||||||||
| 66 | 0 | $notes->set('tracking-pid-'.$stash->{'pid'}, $id); | |||||||||
| 67 | 0 | $log->debug('generated tracking_id for pid-'.$stash->{'pid'}); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | return; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||
| 77 | |||||||||||
| 78 | =pod | ||||||||||
| 79 | |||||||||||
| 80 | =encoding UTF-8 | ||||||||||
| 81 | |||||||||||
| 82 | =head1 NAME | ||||||||||
| 83 | |||||||||||
| 84 | Log::Saftpresse::Plugin::Role::Tracking - role for plugins to implement transaction tracking | ||||||||||
| 85 | |||||||||||
| 86 | =head1 VERSION | ||||||||||
| 87 | |||||||||||
| 88 | version 1.5 | ||||||||||
| 89 | |||||||||||
| 90 | =head1 AUTHOR | ||||||||||
| 91 | |||||||||||
| 92 | Markus Benning <ich@markusbenning.de> | ||||||||||
| 93 | |||||||||||
| 94 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 95 | |||||||||||
| 96 | This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. | ||||||||||
| 97 | |||||||||||
| 98 | This is free software, licensed under: | ||||||||||
| 99 | |||||||||||
| 100 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||