in reply to getting automatic error checking with Win32::OLE and Moose
Here the role could be applied to any of your wrapper classes as long as they provide methods to get the wrapped object, the validation logic and the $rcref.package Automatic::Check; use Moose::Role; requires qw(wrapped check_ref assert_check_ref); sub call { my $self = shift; my $method = shift; my $check_ref = $self->check_ref; $self->wrapped->$method(@_, $check_ref); $self->assert_check_ref($check_ref); warn 'ok'; } package FakeOLE; sub new { bless {} } sub LoadObjects { my $self = shift; my $cfg = shift; $_[0] = $cfg ? 0 : -1; } package SA::Application; use Moose; has wrapped => ( is => 'ro', builder => '_build_ole'); with qw/Automatic::Check/; sub _build_ole { return FakeOLE->new; } sub check_ref { 1 } sub assert_check_ref { my ($self, $check_ref) = @_; die "error" unless ( $check_ref == 0 ); } package main; my $cfg = 'somefile.cfg'; my $sa = SA::Application->new(); $sa->call('LoadObjects', $cfg); # ok $sa->call('LoadObjects', 0); # dies
|
|---|