Saftpresse/Plugin/Role/Tracking.pm

filter: Statementstmt 22.4% 11 / 49 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 4 totaltotal 18.4% 14 / 76 SCAR 40.2
CC
9
Cov
17%
set_tracking_id
20.0
get_tracking_id
20.0
clear_tracking_id
6.0
CRAP 55.4
« Saftpresse/Output/Graphite.pm ↑ Summary Saftpresse/Plugin/GraphitLineFormat.pm »
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
BranchTrueFalseTotal
unless (defined $key) 0 0 0
14 0 $key = $stash->{$by};
15 }
16 0 ▶ if( ! defined $key ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
17 0 my $id = $stash->{'tracking_id'};
18 0 ▶ if( ! defined $id ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 0 0 0
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
BranchTrueFalseTotal
unless (defined $key) 0 0 0
29 0 $key = $stash->{$by};
30 }
31 0 ▶ if( ! defined $key ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
32  
33 0 my $id = $notes->get("tracking-$by-$key");
34 0 ▶ if( defined $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) { } 0 0 0
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
BranchTrueFalseTotal
unless (defined $key) 0 0 0
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
BranchTrueFalseTotal
if (defined $stash->{"pid"}) 0 0 0
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
« Saftpresse/Output/Graphite.pm ↑ Summary Saftpresse/Plugin/GraphitLineFormat.pm »