Authentication/Handler/Size.pm

filter: Statementstmt 89.3% 42 / 47 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 12.5% 1 / 8 totaltotal 77.7% 56 / 72 CC 5 SCAR 8.3
CC
5
Cov
86%
close_callback
5.0
default_config
2.0
grafana_rows
2.0
CRAP 2.3
« Authentication/HTDocs.pm ↑ Summary Authentication/App/ProcessLog/App.pm »
1 package Mail::Milter::Authentication::Handler::Size;
2 2 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for message size metrics
7 2 our $VERSION = '4.20261116'; # VERSION
8 2 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub default_config {
Subroutine default_config: not called CC=1 SCAR=6.9
Pod undocumented
11 0 return {};
12 }
13  
14 0 ▶sub grafana_rows {
Subroutine grafana_rows: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ( $self ) = @_;
16 0 my @rows;
17 0 push @rows, $self->get_json( 'Size_metrics' );
18 0 return \@rows;
19 }
20  
21 1 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
22 return {
23 1 'size_total' => 'The number of emails processed for Size',
24 'size_header_bytes_added_total' => 'The header size added to emails processed for Size',
25 'size_header_bytes_total' => 'The header size of emails processed for Size',
26 'size_body_bytes_total' => 'The body size of emails processed for Size',
27 };
28 }
29  
30 1 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=1 SCAR=0.0
Pod undocumented
31 1 my ( $self, $env_from ) = @_;
32 1 $self->{'headersize'} = 0;
33 1 $self->{'bodysize'} = 0;
34 }
35  
36 6 ▶sub header_callback {
Subroutine header_callback: called CC=1 SCAR=0.0
Pod undocumented
37 6 my ( $self, $header, $value ) = @_;
38 6 $self->{ 'headersize' } = $self->{ 'headersize' } + length( $header . ': ' . $value ) + 2;
39 }
40  
41 1 ▶sub body_callback {
Subroutine body_callback: called CC=1 SCAR=0.0
Pod undocumented
42 1 my ( $self, $body_chunk ) = @_;
43 1 $self->{ 'bodysize' } = $self->{ 'bodysize' } + length ( $body_chunk );
44 }
45  
46 1 ▶sub eom_callback {
Subroutine eom_callback: called CC=1 SCAR=0.0
Pod undocumented
47 1 my ($self) = @_;
48 1 $self->metric_count( 'size_total', {}, 1 );
49 1 $self->metric_count( 'size_header_bytes_total', {}, $self->{ 'headersize' } );
50 1 $self->metric_count( 'size_body_bytes_total', {}, $self->{ 'bodysize' } );
51 }
52  
53 1 ▶sub close_callback {
Subroutine close_callback: called CC=5 SCAR=16.2
Pod undocumented
54 1 my ( $self ) = @_;
55  
56 1 my $top_handler = $self->get_top_handler();
57 1 ▶ if ( exists( $top_handler->{'pre_headers'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $top_handler->{"pre_headers"}) 1 0 1
58 1 foreach my $header ( @{ $top_handler->{'pre_headers'} } ) {
59 4 my $size = length( $header->{'field'} ) + length ( $header->{'value'} ) + 3;
60 4 $self->metric_count( 'size_header_bytes_added_total', { where => 'pre', 'header' => $header->{'field'} }, $size );
61 }
62 }
63 1 ▶ if ( exists( $top_handler->{'add_headers'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $top_handler->{"add_headers"}) 1 0 1
64 1 foreach my $header ( @{ $top_handler->{'add_headers'} } ) {
65 1 my $size = length( $header->{'field'} ) + length ( $header->{'value'} ) + 3;
66 1 $self->metric_count( 'size_header_bytes_added_total', { where => 'add', 'header' => $header->{'field'} }, $size );
67 }
68 }
69  
70 1 delete $self->{'bodysize'};
71 1 delete $self->{'headersize'};
72 }
73  
74 2 1;
75  
76 __END__
« Authentication/HTDocs.pm ↑ Summary Authentication/App/ProcessLog/App.pm »