1 |
package CWMP::Response; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use base qw/Class::Accessor/; |
7 |
__PACKAGE__->add_accessor( qw/ |
8 |
debug |
9 |
/); |
10 |
|
11 |
use XML::Generator; |
12 |
use Carp qw/confess/; |
13 |
use Data::Dump qw/dump/; |
14 |
|
15 |
=head1 NAME |
16 |
|
17 |
CWMP::Response - generate SOAP meesage for response |
18 |
|
19 |
=head2 METHODS |
20 |
|
21 |
=head2 new |
22 |
|
23 |
my $response = CWMP::Response->new({ debug => 1 }); |
24 |
|
25 |
=cut |
26 |
|
27 |
sub new { |
28 |
my $class = shift; |
29 |
my $self = $class->SUPER::new( @_ ); |
30 |
|
31 |
warn "created XML::Generator object" if $self->debug; |
32 |
|
33 |
return $self; |
34 |
} |
35 |
|
36 |
|
37 |
my $cwmp = [ cwmp => 'urn:dslforum-org:cwmp-1-0' ]; |
38 |
my $soap = [ soap => "http://schemas.xmlsoap.org/soap/envelope/" ]; |
39 |
|
40 |
=head2 Inform |
41 |
|
42 |
$response->Inform( $state ); |
43 |
|
44 |
=cut |
45 |
|
46 |
sub Inform { |
47 |
my ( $self, $state ) = @_; |
48 |
$self->xml( $state, sub { |
49 |
my ( $X, $state ) = @_; |
50 |
$X->InformResponse( $cwmp, |
51 |
$X->MaxEnvelopes( $cwmp, 1 ) |
52 |
); |
53 |
}); |
54 |
} |
55 |
|
56 |
=head2 GetRPCMethods |
57 |
|
58 |
$response->GetRPCMethods( $state ); |
59 |
|
60 |
=cut |
61 |
|
62 |
sub GetRPCMethods { |
63 |
my ( $self, $state ) = @_; |
64 |
$self->xml( $state, sub { |
65 |
my ( $X, $state ) = @_; |
66 |
$X->GetRPCMethods(); |
67 |
}); |
68 |
}; |
69 |
|
70 |
=head2 Reboot { |
71 |
|
72 |
$response->Reboot( $state ); |
73 |
|
74 |
=cut |
75 |
|
76 |
sub Reboot { |
77 |
my ( $self, $state ) = @_; |
78 |
$self->xml( $state, sub { |
79 |
my ( $X, $state ) = @_; |
80 |
$X->Reboot(); |
81 |
}); |
82 |
} |
83 |
|
84 |
=head2 GetParameterNames { |
85 |
|
86 |
$response->GetParameterNames( $state, ); |
87 |
|
88 |
=cut |
89 |
|
90 |
sub GetParameterNames { |
91 |
my ( $self, $state ) = @_; |
92 |
$self->xml( $state, sub { |
93 |
my ( $X, $state ) = @_; |
94 |
$X->GetParameterNames( $cwmp, |
95 |
$X->ParameterPath( $cwmp, ''), |
96 |
$X->NextLevel( $cwmp, 0 ), |
97 |
); |
98 |
}); |
99 |
} |
100 |
=head2 xml |
101 |
|
102 |
Used to implement methods which modify just body of soap message. |
103 |
For examples, see source of this module. |
104 |
|
105 |
=cut |
106 |
|
107 |
sub xml { |
108 |
my $self = shift; |
109 |
|
110 |
my ( $state, $closure ) = @_; |
111 |
|
112 |
confess "no state?" unless ($state); |
113 |
confess "no body closure" unless ( $closure ); |
114 |
|
115 |
confess "no ID in state ", dump( $state ) unless ( $state->{ID} ); |
116 |
|
117 |
#warn "state used to generate xml = ", dump( $state ) if $self->debug; |
118 |
|
119 |
my $X = XML::Generator->new(':pretty'); |
120 |
|
121 |
return $X->Envelope( $soap, { 'soap:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" }, |
122 |
$X->Header( $soap, |
123 |
$X->ID( $cwmp, { mustUnderstand => 1 }, $state->{ID} ), |
124 |
$X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ), |
125 |
), |
126 |
$X->Body( $soap, $closure->( $X, $state ) ), |
127 |
); |
128 |
} |
129 |
|
130 |
1; |