/usr/share/perl5/Data/Stag/ChainHandler.pm is in libdata-stag-perl 0.14-2.
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | package Data::Stag::ChainHandler;
=head1 NAME
Data::Stag::ChainHandler - Chain Handler
=head1 SYNOPSIS
=cut
=head1 DESCRIPTION
=head1 PUBLIC METHODS -
=cut
use strict;
use base qw(Data::Stag::Base Data::Stag::Writer);
use vars qw($VERSION);
$VERSION="0.14";
sub init {
my $self = shift;
return;
}
sub subhandlers {
my $self = shift;
$self->{_subhandlers} = shift if @_;
return $self->{_subhandlers};
}
sub blocked_event {
my $self = shift;
if (@_) {
my $e = shift;
$self->{_blocked_event} = $e;
unless (ref($e)) {
$e = [$e];
}
my %h = map {$_=>1} @$e;
$self->blocked_event_h(\%h);
}
return $self->{_blocked_event};
}
sub blocked_event_h {
my $self = shift;
$self->{_blocked_event_h} = shift if @_;
return $self->{_blocked_event_h};
}
sub is_blocked {
my $self = shift;
my $e = shift;
if (!$e) {
$self->throw("must pass arg to is_blocked");
}
my $is = $self->blocked_event_h->{$e};
return $is;
}
sub start_event {
my $self = shift;
my $ev = shift;
my $stack = $self->elt_stack;
push(@$stack, $ev);
my $sh = $self->subhandlers;
my $is_blocked = grep {$self->is_blocked($_)} @$stack;
if ($is_blocked) {
$sh->[0]->start_event($ev);
}
else {
foreach (@$sh) {
$_->start_event($ev);
}
}
}
sub evbody {
my $self = shift;
my $ev = shift;
my @args = @_;
my $stack = $self->elt_stack;
my $sh = $self->subhandlers;
if (grep {$self->is_blocked($_)} @$stack) {
$sh->[0]->evbody($ev, @args);
}
else {
foreach (@$sh) {
$_->evbody($ev, @args);
}
}
return;
}
sub end_event {
my $self = shift;
my $ev = shift;
my $stack = $self->elt_stack;
$ev = pop @$stack;
if (!$ev) {
$self->throw("no event name on stack");
}
my $sh = $self->subhandlers;
my $inside_blocked = grep {$self->is_blocked($_)} @$stack;
if ($self->is_blocked($ev) &&
!$inside_blocked) {
# condition:
# end of a blocked event, and we are
# not inside another blocked event
my ($h, @rest) = @$sh;
my @R = $h->end_event($ev);
foreach my $handler (@rest) {
if (@R) {
$handler->event(@$_) foreach @R;
@$_ = () foreach @R;
}
}
my $tree = $h->tree;
$tree->free;
}
else {
if (grep {$self->is_blocked($_)} @$stack) {
$sh->[0]->end_event($ev);
}
else {
foreach (@$sh) {
$_->end_event($ev);
}
}
}
}
1;
|