Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by Arunbear (Parson)
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.


Comment on Re: getting automatic error checking with Win32::OLE and Moose
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-07-10 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls