| 1 | #!/usr/bin/perl -Ilib -w | ||
| 2 | |||
| 3 | # a formating lib for response processing | ||
| 4 | |||
| 5 | package Net::Server::Framework::Format; | ||
| 6 | |||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use Net::Server::Framework::Errorcodes; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | |||
| 12 | our ($VERSION) = '1.1'; | ||
| 13 | |||
| 14 | # | ||
| 15 | # the hash expected looks like that: | ||
| 16 | # { | ||
| 17 | # timing => delta seconds | ||
| 18 | # ID => unique hash | ||
| 19 | # code => error code | ||
| 20 | # data => { | ||
| 21 | # key1 => val1 | ||
| 22 | # key2 => val2 | ||
| 23 | # ... | ||
| 24 | # } | ||
| 25 | # } | ||
| 26 | # | ||
| 27 | |||
| 28 | sub format { | ||
| 29 | my $hash = shift; | ||
| 30 | delete $hash->{pass}; | ||
| 31 | $hash->{meta}->{duration} = delete $hash->{TIME}; | ||
| 32 | $hash->{meta}->{transaction} = delete $hash->{ID}; | ||
| 33 | $hash->{meta}->{code} = delete $hash->{code}; | ||
| 34 | $hash->{meta}->{user} = delete $hash->{user}; | ||
| 35 | $hash->{meta}->{message} = c2m( $hash->{meta}->{code} ); | ||
| 36 | return $hash; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub c2m { | ||
| 40 | my $code = shift; | ||
| 41 | carp "No error code defined" unless defined $code; | ||
| 42 | |||
| 43 | # find the message | ||
| 44 | my $message = Net::Server::Framework::Errorcodes::c2m($code); | ||
| 45 | return $message; | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | =head1 NAME | ||
| 51 | |||
| 52 | Net::Server::Framework::Fromat - response formatter Net::Server::Framework | ||
| 53 | based daemons | ||
| 54 | |||
| 55 | |||
| 56 | =head1 VERSION | ||
| 57 | |||
| 58 | This documentation refers to Net::Server::Framework::Format version 1.1. | ||
| 59 | |||
| 60 | |||
| 61 | =head1 SYNOPSIS | ||
| 62 | |||
| 63 | A typical invocation looks like this: | ||
| 64 | |||
| 65 | my $answer = Net::Server::Framework::Format::format( $c->{data} ); | ||
| 66 | |||
| 67 | =head1 DESCRIPTION | ||
| 68 | |||
| 69 | This library is used for formatting responses from daemons to a format | ||
| 70 | understood by the client lib. It is meant for mapping error codes to | ||
| 71 | error messages and formatting out debug output oder output not meant for | ||
| 72 | the customer on the other side of the API. | ||
| 73 | |||
| 74 | =head1 BASIC METHODS | ||
| 75 | |||
| 76 | The commands accepted by the lib are: | ||
| 77 | |||
| 78 | =head2 format | ||
| 79 | |||
| 80 | Formating of responses before returning to the requester. | ||
| 81 | |||
| 82 | =head2 c2m | ||
| 83 | |||
| 84 | A wrapper function around error mapping. This can be replaced with your | ||
| 85 | own error mapping functions. | ||
| 86 | |||
| 87 | =head1 BUGS AND LIMITATIONS | ||
| 88 | |||
| 89 | There are no known bugs in this module. | ||
| 90 | Please report problems to | ||
| 91 | Lenz Gschwendtner ( <lenz@springtimesoft.com> ) | ||
| 92 | Patches are welcome. | ||
| 93 | |||
| 94 | =head1 AUTHOR | ||
| 95 | |||
| 96 | Lenz Gschwendtner ( <lenz@springtimesoft.com> ) | ||
| 97 | |||
| 98 | |||
| 99 | |||
| 100 | =head1 LICENCE AND COPYRIGHT | ||
| 101 | |||
| 102 | Copyright (c) | ||
| 103 | 2007 Lenz Gschwerndtner ( <lenz@springtimesoft.comn> ) | ||
| 104 | All rights reserved. | ||
| 105 | |||
| 106 | This module is free software; you can redistribute it and/or | ||
| 107 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||
| 108 | |||
| 109 | This program is distributed in the hope that it will be useful, | ||
| 110 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 111 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||