Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 imbibing at the Monastery: (15)
As of 2015-07-28 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls