Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: getting automatic error checking with Win32::OLE and Moose

by Arunbear (Prior)
on Jan 15, 2013 at 18:21 UTC ( #1013437=note: print w/replies, xml ) Need Help??

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

What about a simpler way:
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
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013437]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-06-23 21:22 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.