Skip to content

Instantly share code, notes, and snippets.

@motemen
Created August 17, 2012 12:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motemen/3378389 to your computer and use it in GitHub Desktop.
Save motemen/3378389 to your computer and use it in GitHub Desktop.
package DBIx::Lite::ResultSet::Role::Slave;
use strict;
use warnings;
use Role::Tiny;
around $_ => sub {
my ($ORIG, $self, @args) = @_;
local $self->{dbix_lite} = $self->{dbix_lite}->master;
return $self->$ORIG(@args);
} for qw(
insert
delete
update
);
1;
package DBIx::Lite::Role::Slave;
use strict;
use warnings;
use Role::Tiny;
requires 'master';
around table => sub {
my ($ORIG, $self, @args) = @_;
my $table = $self->$ORIG(@args);
return Role::Tiny->apply_roles_to_object(
$table, 'DBIx::Lite::ResultSet::Role::Slave',
);
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment