package Automatic:Check; use Moose::Role; around 'load_objects' => sub { my $orig = shift; my $self = shift; $rcref = Variant(VT_I2|VT_BYREF, 0); return $self->$orig(@_, $rcref); }; package SA::Application; use Moose; use 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 { my $self = shift; my $cfg = shift; die "error" unless ( $rcref == 0 ); $self->ole()->LoadObjects($cfg); } package main; my $cfg = 'somefile.cfg'; my $sa = SA::Application->new(); eval { my $sa->load_objects($cfg); }; if ($@) { die $sa->GetLastErrText(); }