/usr/share/perl5/Jifty/Event.pm is in libjifty-perl 1.10518+dfsg-3ubuntu1.
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 | use warnings;
use strict;
package Jifty::Event;
use Jifty::YAML;
use Digest::MD5 qw(md5_hex);
use vars qw/%PUBLISHER/;
=head1 NAME
Jifty::Event - Event objects for publish/subscribe communication
=head1 DESCRIPTION
An event object from the Jifty::PubSub stream.
=head1 METHODS
=head2 new($payload)
Constructor. Takes any kind of payload and blesses a scalar reference to it
into an Event object.
=cut
sub new {
my $class = shift;
my $payload = shift;
bless \$payload, $class;
}
=head2 publish()
Inserts the event into the pubsub stream. If Jifty is configured into
synchronous republishing, then this method runs a C<republish> on itself
with all current subscriptions implicitly. If not, it's simply inserted
into its main channel for asynchronous republishing later.
=cut
sub publish {
my $self = shift;
my $class = ref($self) || $self;
return undef unless (Jifty->config->framework('PubSub')->{'Enable'});
# Always publish to the main stream (needed for async & debugging)
# if ($ASYNC || $DEBUGGING) {
# ($PUBLISHER{$class} ||= Jifty->bus->new_publisher($class))->msg($$self);
# return;
# }
# Synchronized auto-republishing
# TODO - Prioritize current-user subscriptions first?
my $subscriptions = Jifty->bus->modify("$class-subscriptions") || {};
while (my ($channel, $queries) = each %$subscriptions) {
if ($self->filter(@$queries)) {
($PUBLISHER{$channel} ||= Jifty->bus->new_publisher($channel))->msg($$self);
}
}
}
=head2 filter(@query)
Takes multiple class-specific queries, which are evaluated in order by calling L</match>.
=cut
sub filter {
my $self = shift;
$self->match($_) or return 0 for @_;
return 1;
}
=head2 republish(@query)
Run C<filter> with the queries; if they all succeed, the event is republished
into that query-specific channel.
=cut
sub republish {
my $self = shift;
$self->filter(@_) or return;
my $channel = $self->encode_queries(@_);
($PUBLISHER{$channel} ||= Jifty->bus->new_publisher($channel))->msg($$self);
}
=head2 encode_queries(@query)
Encode queries into some sort of canonical MD5 encoding.
=cut
sub encode_queries {
my $self = shift;
my $class = ref($self) || $self;
return $class unless @_;
return $class . '-' . md5_hex(join('', sort map { Jifty::YAML::Dump($_) } @_));
}
=head2 match($query)
Takes a class-specific query and returns whether it matches.
You almost always want to override this; the default implementation
simply always return true;
=cut
sub match {
1;
}
=head2 render_arguments()
A list of additional things to push into the C<%ARGS> of the region that
is about to render this event; see L<Jifty::Subs::Render> for more information.
=cut
sub render_arguments {
();
}
=head2 data()
This event's payload as a scalar value.
=cut
sub data {
${$_[0]}
}
1;
|