File Coverage

blib/lib/Net/DRI/Transport/Defer.pm
Criterion Covered Total %
statement 15 46 32.6
branch 0 8 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod 1 3 33.3
total 21 68 30.8


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, Deferred Transport
2             ##
3             ## Copyright (c) 2008,2009,2013 Patrick Mevzek . All rights reserved.
4             ##
5             ## This file is part of Net::DRI
6             ##
7             ## Net::DRI is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 2 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## See the LICENSE file that comes with this distribution for more details.
13             ####################################################################################################
14              
15             package Net::DRI::Transport::Defer;
16              
17 1     1   848 use strict;
  1         2  
  1         27  
18 1     1   4 use warnings;
  1         1  
  1         23  
19              
20 1     1   5 use base qw(Net::DRI::Transport);
  1         2  
  1         68  
21              
22 1     1   6 use Net::DRI::Exception;
  1         1  
  1         16  
23 1     1   4 use Net::DRI::Util;
  1         1  
  1         313  
24              
25             =pod
26              
27             =head1 NAME
28              
29             Net::DRI::Transport::Defer - Deferred Transport for Net::DRI
30              
31             =head1 DESCRIPTION
32              
33             This module implements a deferred transport in Net::DRI. For now it just dumps all data
34             to a given filehandle, and reports back to Net::DRI that the message has been sent.
35              
36             This is useful for debugging, and also to validate all parameters of an operation without
37             actually sending anything to the registry ; in such way, it is kind of a "simulate" operation
38             where everything is done (parameters validation, message building, etc...) without touching
39             the registry.
40              
41             =head1 METHODS
42              
43             At creation (see Net::DRI C) you pass a reference to an hash, with the following available keys:
44              
45             =head2 protocol_connection
46              
47             Net::DRI class handling protocol connection details. (Ex: C or C)
48              
49             =head2 dump_fh (optional)
50              
51             a filehandle (ex: \*STDERR or an anonymous filehandle) on something already opened for write ;
52             if not defined, defaults to \*STDERR
53              
54             =head1 SUPPORT
55              
56             For now, support questions should be sent to:
57              
58             Enetdri@dotandco.comE
59              
60             Please also see the SUPPORT file in the distribution.
61              
62             =head1 SEE ALSO
63              
64             http://www.dotandco.com/services/software/Net-DRI/
65              
66             =head1 AUTHOR
67              
68             Patrick Mevzek, Enetdri@dotandco.comE
69              
70             =head1 COPYRIGHT
71              
72             Copyright (c) 2008,2009,2013 Patrick Mevzek .
73             All rights reserved.
74              
75             This program is free software; you can redistribute it and/or modify
76             it under the terms of the GNU General Public License as published by
77             the Free Software Foundation; either version 2 of the License, or
78             (at your option) any later version.
79              
80             See the LICENSE file that comes with this distribution for more details.
81              
82             =cut
83              
84             ####################################################################################################
85              
86             sub new
87             {
88 0     0 1   my ($class,$ctx,$rp)=@_;
89 0           my %opts=%$rp;
90              
91 0           my %t=();
92 0 0 0       Net::DRI::Exception::usererr_insufficient_parameters('protocol_connection') unless (exists($opts{protocol_connection}) && $opts{protocol_connection});
93 0           $t{pc}=$opts{protocol_connection};
94 0           Net::DRI::Util::load_module($t{pc},'transport/defer');
95 0 0         if ($t{pc}->can('transport_default'))
96             {
97 0           %opts=($t{pc}->transport_default('defer'),%opts);
98             }
99              
100 0           my $self=$class->SUPER::new($ctx,\%opts);
101 0           $self->name('defer');
102 0           $self->version('0.1');
103 0           $self->has_state(0);
104 0           $self->is_sync(0);
105 0           $self->defer(0);
106 0           $self->current_state(0);
107 0           $self->time_open(time());
108 0           $self->time_used(time());
109              
110 0           $t{exchanges_done}=0;
111 0 0         $t{dump_fh}=(exists($opts{dump_fh}))? $opts{dump_fh} : \*STDERR;
112              
113 0           my @need=qw/read_data write_message/;
114 0 0         Net::DRI::Exception::usererr_invalid_parameters('protocol_connection class ('.$t{pc}.') must have: '.join(' ',@need)) if (grep { ! $t{pc}->can($_) } @need);
  0            
115              
116 0           $self->{transport}=\%t;
117 0           return $self;
118             }
119              
120 0     0 0   sub ping { return 1; }
121              
122             sub send ## no critic (Subroutines::ProhibitBuiltinHomonyms)
123             {
124 0     0 0   my ($self,$ctx,$tosend)=@_;
125 0           my $t=$self->transport_data();
126 0           my $pc=$t->{pc};
127              
128 0           print { $t->{dump_fh} } "\n",$pc->write_message($self,$tosend),"\n";
  0            
129 0           return 1;
130             }
131              
132             ####################################################################################################
133             1;