This file is indexed.

/usr/share/perl5/Mail/MtPolicyd/ConnectionPool.pm is in mtpolicyd 2.02-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Mail::MtPolicyd::ConnectionPool;

use strict;
use warnings;
use MooseX::Singleton;

our $VERSION = '2.02'; # VERSION
# ABSTRACT: a singleton to hold all configure connections

has 'pool' => (
  is => 'ro',
  isa => 'HashRef[Mail::MtPolicyd::Connection]',
  lazy => 1,
  default => sub { {} },
  traits => [ 'Hash' ],
  handles => {
    'get_connection' => 'get',
    'add_connection' => 'set',
  }
);

sub get_handle {
  my ( $self, $name ) = @_;
  if( defined $self->pool->{$name} ) {
    return $self->pool->{$name}->handle;
  }
  return;
}

has 'plugin_prefix' => ( is => 'ro', isa => 'Str',
  default => 'Mail::MtPolicyd::Connection::');

sub load_config {
  my ( $self, $config ) = @_;
  foreach my $name ( keys %$config ) {
    $self->load_connection( $name, $config->{$name} );
  }
  return;
}

sub load_connection {
	my ( $self, $name, $params ) = @_;
	if( ! defined $params->{'module'} ) {
		die('no module defined for connection '.$name.'!');
	}
	my $module = $params->{'module'};
	my $class = $self->plugin_prefix.$module;
	my $conn;

	my $code = "require ".$class.";";
	eval $code; ## no critic (ProhibitStringyEval)
	if($@) {
    die('could not load connection '.$name.': '.$@);
  }

	eval {
    $conn = $class->new(
      name => $name,
      %$params,
    );
    $conn->init();
  };
  if($@) {
    die('could not initialize connection '.$name.': '.$@);
  }
	$self->add_connection( $name => $conn );
	return;
}

sub shutdown {
  my $self = shift;

  foreach my $conn ( values %{$self->pool} ) {
    $conn->shutdown(@_); # cascade
  }

  return;
}

sub reconnect {
  my $self = shift;

  foreach my $conn ( values %{$self->pool} ) {
    $conn->reconnect(@_); # cascade
  }

  return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Mail::MtPolicyd::ConnectionPool - a singleton to hold all configure connections

=head1 VERSION

version 2.02

=head1 AUTHOR

Markus Benning <ich@markusbenning.de>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.

This is free software, licensed under:

  The GNU General Public License, Version 2, June 1991

=cut