in reply to getting automatic error checking with Win32::OLE and Moose

Firstly, your around modifier is broken...

around 'load_objects' => sub { my $orig = shift; my $self = shift; $rcref = Variant(VT_I2|VT_BYREF, 0); return $self->$orig(@_, $rcref); die "error" unless ( $rcref == 0 ); };

The die is after an unconditional return statement, so will never happen.

As I understand it, you have a single wrapper function that you'd like to apply to a lot of methods. But you don't want to hard-code within the wrapper role the names of all those functions.

This is a natural desire; to avoid tightly coupling the wrapper code with the class being wrapped. (See also: Aspect-Oriented Programming.)

Anyhow, although it's still at an early stage of development, my module MooseX::ModifyTaggedMethods might be of help. This allows you to tag methods within a class, and write roles that use these tags to decide which methods to wrap.

package Automatic::Check { use MooseX::RoleQR; use MooseX::ModifyTaggedMethods; around methods_tagged('ShouldCheck') => sub { my $orig = shift; my $self = shift; $rcref = Variant(VT_I2|VT_BYREF, 0); return $self->$orig(@_, $rcref); die "error" unless ( $rcref == 0 ); # never happens }; } package SA::Application { use Moose; use Sub::Talisman qw( ShouldCheck ); with 'Automatic::Check'; has ole => ( is => 'ro', isa => 'Win32::OLE', builder => '_build_ole +'); sub _build_ole { return Win32::OLE->new("SiebelDataServer.ApplicationObject" or die + "failed"; } sub load_objects : ShouldCheck { my $self = shift; my $cfg = shift; $self->ole->LoadObjects($cfg); } }

I don't have Windows, so can't test the above, but it should give you the idea of how it works.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
$orig(@_, $rcref); die unless ( $rcref == 0 ); # never happens }; } package SA::Application { use Moose; use Sub::Talisman qw( ShouldCheck ); with