Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. in my on recv for a websocket..
  2. #I create a hash with the json structure.
  3. my $json = JSON->new->allow_nonref;
  4. my %req = %{ $json->decode( $msg ) };
  5.  
  6. #verify it works and hash is created, all data elements are there..
  7. while (my ($k,$v)=each %req)
  8. {
  9. app->log->debug(sprintf 'JSON: %s : %s', $k, $v);
  10. }
  11.  
  12. #now I want to either perform inserts into database or updates to database.. so I send it off to a helper
  13. $self->upsert(\%req);
  14.  
  15.  
  16.  
  17. ...
  18.  
  19.  
  20. helper upsert => sub
  21. {
  22. my $self = shift;
  23. my %req = %_;
  24. app->log->debug(sprintf 'UPSERT Called');
  25.  
  26.  
  27. while (my ($k,$v)=each %req)
  28. {
  29. app->log->debug(sprintf 'UPSERT: %s : %s', $k, $v);
  30. }
  31.  
  32. #do something useful with hash once I verify it is sane
  33.  
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement