File Coverage

blib/lib/Net/DRI/Data/RegistryObject.pm
Criterion Covered Total %
statement 9 36 25.0
branch 0 16 0.0
condition 0 21 0.0
subroutine 3 6 50.0
pod 0 2 0.0
total 12 81 14.8


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, RegistryObject
2             ##
3             ## Copyright (c) 2005,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::Data::RegistryObject;
16              
17 67     67   1857 use strict;
  67         102  
  67         4854  
18 67     67   285 use warnings;
  67         1636  
  67         4421  
19              
20 67     67   1682 use Net::DRI::Exception;
  67         1112  
  67         25831  
21              
22             our $AUTOLOAD;
23              
24             =pod
25              
26             =head1 NAME
27              
28             Net::DRI::Data::RegistryObject - Additional API for Net::DRI operations
29              
30             =head1 SYNOPSYS
31              
32             my $dri=Net::DRI->new();
33             my $nsg=$dri->remote_object('nsgroup');
34             $nsg->create(...);
35             $nsg->update(...);
36             $nsg->whatever(...);
37              
38             Also:
39             my $nsg=$dri->remote_object('nsgroup','name');
40              
41             =head1 DESCRIPTION
42              
43             For objects other than domains, hosts, or contacts, Net::DRI::Data::RegistryObject
44             can be used to apply actions.
45              
46             Net::DRI::remote_object is used to create a new Net::DRI::Data::RegistryObject
47             with either only one parameter (the object type) or two parameters (the object
48             type and the object name)
49              
50             If the object name is not passed at creation it will need to be passed for all
51             later actions as first parameter.
52              
53             All calls are handled by an AUTOLOAD, except target() which is the same as in Net::DRI.
54              
55             All calls need either two array references (protocol parameters and transport parameters)
56             or a list (protocol parameters only).
57              
58             =head1 SUPPORT
59              
60             For now, support questions should be sent to:
61              
62             Enetdri@dotandco.comE
63              
64             Please also see the SUPPORT file in the distribution.
65              
66             =head1 SEE ALSO
67              
68             Ehttp://www.dotandco.com/services/software/Net-DRI/E
69              
70             =head1 AUTHOR
71              
72             Patrick Mevzek, Enetdri@dotandco.comE
73              
74             =head1 COPYRIGHT
75              
76             Copyright (c) 2005,2013 Patrick Mevzek .
77             All rights reserved.
78              
79             This program is free software; you can redistribute it and/or modify
80             it under the terms of the GNU General Public License as published by
81             the Free Software Foundation; either version 2 of the License, or
82             (at your option) any later version.
83              
84             See the LICENSE file that comes with this distribution for more details.
85              
86             =cut
87              
88              
89             ###########################################################################################################
90              
91             sub new
92             {
93 0     0 0   my ($class,$p,$type,$name)=@_; ## $name (object name) not necessarily defined
94              
95 0 0 0       Net::DRI::Exception::err_invalid_parameters() unless (defined($p) && ((ref($p) eq 'Net::DRI') || (ref($p) eq 'Net::DRI::Registry')));
      0        
96 0 0 0       Net::DRI::Exception::err_insufficient_parameters() unless (defined($type) && $type);
97              
98 0           my $self={
99             p => $p,
100             type => $type,
101             name => $name,
102             };
103              
104 0           bless($self,$class);
105 0           return $self;
106             }
107              
108             sub target
109             {
110 0     0 0   my ($self,@args)=@_;
111 0           $self->{p}->target(@args);
112 0           return $self;
113             }
114              
115             sub AUTOLOAD ## no critic (Subroutines::RequireFinalReturn)
116             {
117 0     0     my ($self,@args)=@_;
118 0           my $attr=$AUTOLOAD; ## this is the action wanted on the object
119 0           $attr=~s/.*:://;
120 0 0         return unless $attr=~m/[^A-Z]/; ## skip DESTROY and all-cap methods
121              
122 0           my $name=$self->{name};
123 0           my ($rp,$rt);
124 0 0 0       if (@args==2 && (ref $args[0] eq 'ARRAY') && (ref $args[1] eq 'ARRAY'))
      0        
125             {
126 0           $rp=$args[0];
127 0 0 0       $rp=[ $self->{name}, @$rp ] if (defined $name && $name);
128 0           $rt=$args[1];
129             } else
130             {
131 0 0 0       $rp=(defined $name && $name)? [ $name, @args ] : [ @args ];
132 0           $rt=[];
133             }
134              
135 0           my $p=$self->{p};
136 0 0         if (ref $p eq 'Net::DRI::Registry')
    0          
137             {
138 0           return $p->process($self->{type},$attr,$rp,$rt);
139             } elsif (ref $p eq 'Net::DRI')
140             {
141 0           my $c=$self->{type}.'_'.$attr;
142 0           return $p->$c->(@$rp);
143             } else
144             {
145 0           Net::DRI::Exception::err_assert('case not handled: '.ref($p));
146             }
147             }
148              
149             ###########################################################################################################
150             1;