File Coverage

blib/lib/Parallel/Workers/Transaction.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Parallel::Workers::Transaction;
2              
3 1     1   3564 use warnings;
  1         3  
  1         35  
4 1     1   7 use strict;
  1         3  
  1         35  
5 1     1   7 use Carp;
  1         2  
  1         78  
6 1     1   7 use Data::Dumper;
  1         2  
  1         51  
7 1     1   4051 use threads::shared;
  1         2824  
  1         10  
8 1     1   1192 use Parallel::Workers::Shared;
  0            
  0            
9              
10             our (@ISA, @EXPORT, @EXPORT_OK);
11             @ISA = qw(Exporter);
12              
13             @EXPORT = qw(TRANSACTION_CONT TRANSACTION_TERM);
14             @EXPORT_OK = ();
15              
16             use constant TRANSACTION_CONT=>"CONT";
17             use constant TRANSACTION_TERM=>"TERM";
18              
19              
20             # Module implementation here
21             # init the transaction for n workers
22             # error=>TRANSACTION_CONT, enable=>1, type => SCALAR,check => 0, regex=> undef
23             sub new {
24             my $class:shared = shift;
25             my %args = @_;
26              
27             my $this={
28             error =>(defined $args{error})?$args{error}:TRANSACTION_CONT,
29             enable=>(defined $args{enable})?$args{enable}:1,
30             type =>(defined $args{type})?$args{type}:"SCALAR",
31             check =>$args{check},
32             regex =>$args{regex}
33             };
34            
35            
36             bless $this, $class;
37             return $this;
38             }
39              
40              
41             sub check{
42             my $this=shift;
43             my ($tid, $result)=@_;
44            
45             return TRANSACTION_CONT unless $this->{enable};
46            
47             return $this->{error} unless ($this->{type} eq ref(\$result));
48            
49             if (defined $this->{regex}){
50             my $reg=qr/$this->{regex}/;
51             # my $reg=qr/$this->{regex}/;
52             # print "INFO:regex detected".$this->{regex}."\n" unless defined $result || $result=~ $reg ;
53             return $this->{error} unless defined $result ;
54             return $this->{error} unless $result=~ $this->{regex} ;
55             }
56            
57             if (defined $this->{check}){
58             return $this->{error} unless $result=$this->{check};
59             }
60            
61             return TRANSACTION_CONT;
62             }
63              
64              
65              
66             1; # Magic true value required at end of module
67             __END__