DBIx::Class::ResultSet::ModifyMethods - Wrap modifiers around your methods
Given a DBIx::Class::ResultSet that consumes this component, such as the following:
package MySchema::ResultSet::Bar; use strict; use warnings; use base 'DBIx::Class::ResultSet'; __PACKAGE__->load_components('ResultSet::ModifyMethods'); ## Additional custom resultset methods, if any 1;
Then later when you have a resulset of that class:
my $rs = $schema->resultset('Bar');
You can modify instance methods similarly to Moose method modifiers.
$rs->around( search => sub { my ($orig, $rs, @args) = @_; print "Search was called!"; return $rs->$orig(@args); });
The above would wrap the search method such that when someone called it on $rs you'd see "Search was called!"" in STDOUT
$rs
There may be times when you wish to hook a resultset before passing a resultset to another method. Since the anonymous coderef can be a closure, this opens some possibilties for enabling observer style patterns. You can also use this to modify @args, etc, just as in Moose, or even change the return value.
@args
This component defines the following methods.
Arguments: $method||\@methods, $coderef Returns: Wrapped ResultSet (A Proxy instance)
Allows you to dynamically add a Moose style around method modifier for this single ResultSet only which wraps a method or arrayref of methods and grants you full control over how the wrapped method is called. You can even use this to inspect and modify arguments.
Example:
$rs->around( search => sub { my ($orig, $rs, @args) = @_; return $rs->$orig(@args); });
Allows you to run some code before a method or arrayref of methods on your ResultSet instance before it actually runs. You can't use this to modify incoming args to a method or control the method. Use this to safely hook a method when you want to do something and not potentially effect the actually running of the wrapped method.
args
$rs->before( search => sub { my ($rs, @args) = @_; return $rs->$orig(@args); });
Allows you to run some code before a method or arrayref of methods on your ResultSet instance after it actually runs. You can't use this to modify incoming args to a method or control the method. Use this to safely hook a method when you want to do something and not potentially effect the actually running of the wrapped method.
$rs->after( search => sub { my ($rs, @args) = @_; return $rs->$orig(@args); });
John Napiorkowski email:jjnapiork@cpan.org
DBIx::Class
Copyright 2017, John Napiorkowski email:jjnapiork@cpan.org
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::Class::ResultSet::ModifyMethods, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::ResultSet::ModifyMethods
CPAN shell
perl -MCPAN -e shell install DBIx::Class::ResultSet::ModifyMethods
For more information on module installation, please visit the detailed CPAN module installation guide.