/[cwmp]/google/trunk/lib/CWMP/Request.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/trunk/lib/CWMP/Request.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 200 by dpavlin, Wed Nov 14 19:23:32 2007 UTC revision 223 by dpavlin, Sat Nov 24 02:17:40 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use XML::Rules;  use XML::Rules;
 use CWMP::Tree;  
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use Carp qw/confess cluck/;  use Carp qw/confess cluck/;
9  use Class::Trigger;  use Class::Trigger;
# Line 19  All methods described below call trigger Line 18  All methods described below call trigger
18    
19  =cut  =cut
20    
 my $tree = CWMP::Tree->new({ debug => 0 });  
   
21  our $state;     # FIXME check this!  our $state;     # FIXME check this!
22    
23  my $rules =  [  our $rules =  [
24                  #_default => 'content trim',                  #_default => 'content trim',
25                  x_default => sub {                  x_default => sub {
26                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;                          my ($tag_name, $tag_hash, $context, $parent_data) = @_;
# Line 56  my $rules =  [ Line 53  my $rules =  [
53                          # Name/Value tags must be case insnesitive                          # Name/Value tags must be case insnesitive
54                          my $value = (grep( /value/i, keys %$tag_hash ))[0];                          my $value = (grep( /value/i, keys %$tag_hash ))[0];
55                          $state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' );                          $state->{Parameter}->{ _tag($tag_hash, 'Name', '_content') } = _tag($tag_hash, 'Value', '_content' );
56                            $state->{_trigger} = 'ParameterValue';
57                  },                  },
58    
59  ];  ];
# Line 96  push @$rules, Line 94  push @$rules,
94    
95                          confess "need state" unless ( $state ); # don't remove!                          confess "need state" unless ( $state ); # don't remove!
96    
97                          # XXX dragons ahead: convert name to tree rewriting it into perl                          $state->{ParameterInfo}->{$name} = $writable;
                         my $s = '$state->{ParameterInfo}->' . $tree->name2perl( $name ) . "->{writable} = $writable;";  
                         eval "$s";  
                         confess "can't eval $s : $@" if ($@);  
98    
99                          #warn "## state = dump( $state ), "\n";                          #warn "## state = dump( $state ), "\n";
100    
# Line 121  push @$rules, Line 116  push @$rules,
116                          $state->{_trigger} = 'Fault';                          $state->{_trigger} = 'Fault';
117                  };                  };
118    
 my $parser = XML::Rules->new(  
 #       start_rules => [  
 #               '^division_name,fax' => 'skip',  
 #       ],  
         namespaces => {  
                 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',  
                 'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',  
                 'http://www.w3.org/2001/XMLSchema' => 'xsd',  
                 'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',  
                 'urn:dslforum-org:cwmp-1-0' => '',  
         },  
         rules => $rules,  
 );  
   
119  =head1 METHODS  =head1 METHODS
120    
121  =head2 parse  =head2 parse
# Line 143  my $parser = XML::Rules->new( Line 124  my $parser = XML::Rules->new(
124    
125  =cut  =cut
126    
127    my $parser = XML::Rules->new(
128    #               start_rules => [
129    #                       '^division_name,fax' => 'skip',
130    #               ],
131                    namespaces => {
132                            'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv',
133                            'http://schemas.xmlsoap.org/soap/encoding/' => 'soap',
134                            'http://www.w3.org/2001/XMLSchema' => 'xsd',
135                            'http://www.w3.org/2001/XMLSchema-instance' => 'xsi',
136                            'urn:dslforum-org:cwmp-1-0' => '',
137                    },
138                    rules => $rules,
139    );
140    
141  sub parse {  sub parse {
142          my $self = shift;          my $self = shift;
143    
144          my $xml = shift || confess "no xml?";          my $xml = shift || confess "no xml?";
145    
146          $state = {};          $state = {};
147    
148          $parser->parsestring( $xml );          $parser->parsestring( $xml );
149          if ( my $trigger = $state->{_trigger} ) {          if ( my $trigger = $state->{_trigger} ) {
150                  __PACKAGE__->call_trigger( $trigger, $state );                  warn "### call_trigger( $trigger )\n";
151                    $self->call_trigger( $trigger, $state );
152          }          }
153          # XXX don't propagate _trigger (useful?)          # XXX don't propagate _trigger (useful?)
154          delete( $state->{_trigger} );          delete( $state->{_trigger} );

Legend:
Removed from v.200  
changed lines
  Added in v.223

  ViewVC Help
Powered by ViewVC 1.1.26