This file is indexed.

/usr/share/perl5/Rex/Notify.pm is in rex 1.4.1-1.

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
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

package Rex::Notify;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

sub new {
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = {@_};

  bless( $self, $proto );

  $self->{__types__}             = {};
  $self->{__postponed__}         = [];
  $self->{__running_postponed__} = 0;
  $self->{__in_notify__}         = 0;

  return $self;
}

sub add {
  my ( $self, %option ) = @_;

  return if ( $self->{__in_notify__} );

  if ( exists $self->{__types__}->{ $option{type} }->{ $option{name} } ) {
    Rex::Logger::debug(
      "A resource of the type $option{type} and name $option{name}"
        . "already exists.",
      "warn"
    );
    return;
  }

  $self->{__types__}->{ $option{type} }->{ $option{name} } = {
    postpone => $option{postpone} || 0,
    options  => $option{options},
    cb       => $option{cb},
  };
}

sub run {
  my ( $self, %option ) = @_;

  Rex::Logger::debug("Try to notify $option{type} -> $option{name}");

  if ( exists $self->{__types__}->{ $option{type} }
    && exists $self->{__types__}->{ $option{type} }->{ $option{name} }
    && exists $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb}
    && $self->{__types__}->{ $option{type} }->{ $option{name} }->{postpone} ==
    0 )
  {
    Rex::Logger::debug("Running notify $option{type} -> $option{name}");

    my $cb = $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb};

    $self->{__in_notify__} = 1;

    $cb->(
      $self->{__types__}->{ $option{type} }->{ $option{name} }->{options} );

    $self->{__in_notify__} = 0;
  }
  else {
    if ( !$self->{__running_postponed__} ) {
      Rex::Logger::debug(
        "Can't notify $option{type} -> $option{name}. Postponing...");
      $self->_postpone(%option);
    }
    else {
      Rex::Logger::info(
        "Can't run postponed notification. "
          . "Resource not found ($option{type} -> $option{name})",
        "warn"
      );
    }
  }

}

sub run_postponed {
  my ($self) = @_;
  $self->{__running_postponed__} = 1;
  Rex::Logger::debug("Running postponed notifications.");
  for my $p ( @{ $self->{__postponed__} } ) {
    $self->run( %{$p} );
  }
}

sub _postpone {
  my ( $self, %option ) = @_;
  push @{ $self->{__postponed__} }, \%option;
}

1;