[Rt-commit] r6263 - in MessageBus: lib lib/MessageBus
audreyt at bestpractical.com
audreyt at bestpractical.com
Tue Oct 24 21:24:47 EDT 2006
Author: audreyt
Date: Tue Oct 24 21:24:46 2006
New Revision: 6263
Modified:
MessageBus/Makefile.PL
MessageBus/lib/MessageBus.pm
MessageBus/lib/MessageBus/Pub.pm
MessageBus/lib/MessageBus/Sub.pm
Log:
* This be 0.02.
Modified: MessageBus/Makefile.PL
==============================================================================
--- MessageBus/Makefile.PL (original)
+++ MessageBus/Makefile.PL Tue Oct 24 21:24:46 2006
@@ -7,6 +7,6 @@
requires 'DBM::Deep';
requires 'Data::UUID';
-requires 'Class::InsideOut';
+requires 'Class::Accessor::Fast';
sign; WriteAll;
Modified: MessageBus/lib/MessageBus.pm
==============================================================================
--- MessageBus/lib/MessageBus.pm (original)
+++ MessageBus/lib/MessageBus.pm Tue Oct 24 21:24:46 2006
@@ -1,16 +1,16 @@
package MessageBus;
-$MessageBus::VERSION = '0.01';
+$MessageBus::VERSION = '0.02';
use 5.005;
use strict;
-use Class::InsideOut qw( public private register id );
use MessageBus::Pub;
use MessageBus::Sub;
+use base qw/Class::Accessor::Fast/;
-private cache => my %cache;
+__PACKAGE__->mk_accessors(qw/_cache/);
sub new {
- my $id = id( my $self = register( bless \(my $s), shift ) );
+ my $self = bless {}, shift;
my $backend = shift || 'PlainHash';
@@ -18,18 +18,18 @@
eval { require "MessageBus/Cache/$backend.pm" }
or die "Cannot load backend module: MessageBus::Cache::$backend: $@";
- $cache{$id} = "MessageBus::Cache::$backend"->new(@_);
+ $self->_cache("MessageBus::Cache::$backend"->new(@_));
return $self;
}
sub publish {
- my $id = id(my $self = shift);
- MessageBus::Pub->new($cache{$id}, @_ ? @_ : '');
+ my $self = shift;
+ MessageBus::Pub->new($self->_cache, @_ ? @_ : '');
}
sub subscribe {
- my $id = id(my $self = shift);
- MessageBus::Sub->new($cache{$id}, @_ ? @_ : '');
+ my $self = shift;
+ MessageBus::Sub->new($self->_cache, @_ ? @_ : '');
}
1;
Modified: MessageBus/lib/MessageBus/Pub.pm
==============================================================================
--- MessageBus/lib/MessageBus/Pub.pm (original)
+++ MessageBus/lib/MessageBus/Pub.pm Tue Oct 24 21:24:46 2006
@@ -1,32 +1,28 @@
package MessageBus::Pub;
use strict;
use Data::UUID;
-use Class::InsideOut qw( public private register id );
+use base qw/Class::Accessor::Fast/;
-public chan => my %chan;
-private uuid => my %uuid;
-private cache => my %cache;
+__PACKAGE__->mk_accessors(qw/chan _uuid _cache/);
sub new {
my ($class, $cache, @chan) = @_;
- my $id = id( my $self = register( bless \(my $s), shift ) );
- $chan{$id} = \@chan;
- $uuid{$id} = Data::UUID->new->create_b64;
- $cache{$id} = $cache;
- $cache->add_publisher($_, $uuid{$id}) for @chan;
+ my $uuid = Data::UUID->new->create_b64;
+ my $self = bless({ _cache => $cache, chan => \@chan, _uuid => $uuid });
+ $cache->add_publisher($_, $uuid) for @chan;
return $self;
}
sub msg {
- my $id = id(my $self = shift);
+ my $self = shift;
my $msg = shift;
- $cache{$id}->put($_, $uuid{$id}, $msg) for @{$chan{$id}};
+ $self->_cache->put($_, $self->_uuid, $msg) for @{$self->chan};
}
no warnings 'redefine';
sub DESTROY {
- my $id = id(my $self = shift);
- $cache{$id}->remove_publisher($_, $uuid{$id}) for @{$chan{$id}};
+ my $self = shift;
+ $self->_cache->remove_publisher($_, $self->_cache) for @{$self->chan};
}
1;
Modified: MessageBus/lib/MessageBus/Sub.pm
==============================================================================
--- MessageBus/lib/MessageBus/Sub.pm (original)
+++ MessageBus/lib/MessageBus/Sub.pm Tue Oct 24 21:24:46 2006
@@ -1,41 +1,41 @@
package MessageBus::Sub;
use strict;
-use Class::InsideOut qw( public private register id );
+use base qw/Class::Accessor::Fast/;
-public chan => my %chan;
-private pubs => my %pubs;
-private cache => my %cache;
+__PACKAGE__->mk_accessors(qw/chan _pubs _cache/);
sub new {
my ($class, $cache, @chan) = @_;
- my $id = id( my $self = register( bless \(my $s), shift ) );
- $pubs{$id} = { map { $_ => $cache->publisher_indices($_); } @chan };
- $cache{$id} = $cache;
- $chan{$id} = \@chan;
+ my $pubs = { map { $_ => $cache->publisher_indices($_); } @chan };
+ my $self = bless({ chan => \@chan, _cache => $cache, _pubs => $pubs });
return $self;
}
sub get_all {
- my $id = id(my $self = shift);
+ my $self = shift;
+ my $pubs = $self->_pubs;
+ my $cache = $self->_cache;
return {
map {
- my $orig = $pubs{$id}{$_};
- $pubs{$id}{$_} = $cache{$id}->publisher_indices($_);
- $_ => [$cache{$id}->get($_, $orig, $pubs{$id}{$_})];
- } @{$chan{$id}}
+ my $orig = $pubs->{$_};
+ $pubs->{$_} = $cache->publisher_indices($_);
+ $_ => [$cache->get($_, $orig, $pubs->{$_})];
+ } @{$self->chan}
};
}
sub get {
- my $id = id(my $self = shift);
- my $chan = @_ ? shift : $chan{$id}[0];
+ my $self = shift;
+ my $pubs = $self->_pubs;
+ my $cache = $self->_cache;
+ my $chan = @_ ? shift : $self->chan->[0];
- my $orig = $pubs{$id}{$chan};
- $pubs{$id}{$chan} = $cache{$id}->publisher_indices($chan);
+ my $orig = $pubs->{$chan};
+ $pubs->{$chan} = $cache->publisher_indices($chan);
wantarray
- ? map {$_->[1]} $cache{$id}->get($chan, $orig, $pubs{$id}{$chan})
- : [map {$_->[1]} $cache{$id}->get($chan, $orig, $pubs{$id}{$chan})];
+ ? map {$_->[1]} $cache->get($chan, $orig, $pubs->{$chan})
+ : [map {$_->[1]} $cache->get($chan, $orig, $pubs->{$chan})];
}
1;
More information about the Rt-commit
mailing list