[BACK]Return to json.pm CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo-REST-API / lib / Text / Todo / REST / API / Representations

Annotation of todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Representations/json.pm, Revision 1.3

1.1       andrew      1: package Text::Todo::REST::API::Representations::json;
                      2:
1.3     ! andrew      3: # $AFresh1: json.pm,v 1.2 2010/01/31 04:31:34 andrew Exp $
1.1       andrew      4:
                      5: use base 'Text::Todo::REST::API::Representations';
                      6:
                      7: use warnings;
                      8: use strict;
                      9: use Carp;
                     10:
                     11: use version; our $VERSION = qv('0.0.1');
                     12:
                     13: use JSON;
                     14:
                     15: {
1.2       andrew     16:     sub content_type { return 'application/json' }
1.1       andrew     17:
                     18:     sub can_render {
                     19:         my ( $class, $format ) = @_;
                     20:         return if !defined $format;
                     21:
                     22:         my %handled_formats = map { $_ => 1 } qw(
1.3     ! andrew     23:             json
1.1       andrew     24:         );
                     25:
                     26:         return exists $handled_formats{$format};
                     27:     }
                     28:
                     29:     sub render_files {
                     30:         my ( $self, $format, $data ) = @_;
                     31:
                     32:         $data ||= [];
                     33:
                     34:         return to_json($data);
                     35:     }
                     36:
                     37:     sub render_list {
                     38:         my ( $self, $format, $input ) = @_;
                     39:
                     40:         return if !defined $input;
                     41:
                     42:         my @input = $input;
                     43:         if ( ref $input eq 'ARRAY' ) {
                     44:             @input = @{$input};
                     45:         }
                     46:
                     47:         return to_json(\@input);
                     48:     }
                     49:
                     50:     sub render_entry {
                     51:         my ( $self, $format, $input ) = @_;
                     52:         return to_json($input);
                     53:     }
                     54: }
                     55:
                     56: 1;    # Magic true value required at end of module
                     57: __END__
                     58:
                     59: =head1 NAME
                     60:
                     61: Text::Todo::REST::API::json - [One line description of module's purpose here]
                     62:
                     63:
                     64: =head1 VERSION
                     65:
                     66: This document describes Text::Todo::REST::API::json version 0.0.1
                     67:
                     68:
                     69: =head1 SYNOPSIS
                     70:
                     71:     use Text::Todo::REST::API::json;
                     72:
                     73: =for author to fill in:
                     74:     Brief code example(s) here showing commonest usage(s).
                     75:     This section will be as far as many users bother reading
                     76:     so make it as educational and exeplary as possible.
                     77:
                     78:
                     79: =head1 DESCRIPTION
                     80:
                     81: =for author to fill in:
                     82:     Write a full description of the module and its features here.
                     83:     Use subsections (=head2, =head3) as appropriate.
                     84:
                     85:
                     86: =head1 INTERFACE
                     87:
                     88: =for author to fill in:
                     89:     Write a separate section listing the public components of the modules
                     90:     interface. These normally consist of either subroutines that may be
                     91:     exported, or methods that may be called on objects belonging to the
                     92:     classes provided by the module.
                     93:
                     94:
                     95: =head1 DIAGNOSTICS
                     96:
                     97: =for author to fill in:
                     98:     List every single error and warning message that the module can
                     99:     generate (even the ones that will "never happen"), with a full
                    100:     explanation of each problem, one or more likely causes, and any
                    101:     suggested remedies.
                    102:
                    103: =over
                    104:
                    105: =item C<< Error message here, perhaps with %s placeholders >>
                    106:
                    107: [Description of error here]
                    108:
                    109: =item C<< Another error message here >>
                    110:
                    111: [Description of error here]
                    112:
                    113: [Et cetera, et cetera]
                    114:
                    115: =back
                    116:
                    117:
                    118: =head1 CONFIGURATION AND ENVIRONMENT
                    119:
                    120: =for author to fill in:
                    121:     A full explanation of any configuration system(s) used by the
                    122:     module, including the names and locations of any configuration
                    123:     files, and the meaning of any environment variables or properties
                    124:     that can be set. These descriptions must also include details of any
                    125:     configuration language used.
                    126:
                    127: Text::Todo::REST::API::json requires no configuration files or environment variables.
                    128:
                    129:
                    130: =head1 DEPENDENCIES
                    131:
                    132: =for author to fill in:
                    133:     A list of all the other modules that this module relies upon,
                    134:     including any restrictions on versions, and an indication whether
                    135:     the module is part of the standard Perl distribution, part of the
                    136:     module's distribution, or must be installed separately. ]
                    137:
                    138: None.
                    139:
                    140:
                    141: =head1 INCOMPATIBILITIES
                    142:
                    143: =for author to fill in:
                    144:     A list of any modules that this module cannot be used in conjunction
                    145:     with. This may be due to name conflicts in the interface, or
                    146:     competition for system or program resources, or due to internal
                    147:     limitations of Perl (for example, many modules that use source code
                    148:     filters are mutually incompatible).
                    149:
                    150: None reported.
                    151:
                    152:
                    153: =head1 BUGS AND LIMITATIONS
                    154:
                    155: =for author to fill in:
                    156:     A list of known problems with the module, together with some
                    157:     indication Whether they are likely to be fixed in an upcoming
                    158:     release. Also a list of restrictions on the features the module
                    159:     does provide: data types that cannot be handled, performance issues
                    160:     and the circumstances in which they may arise, practical
                    161:     limitations on the size of data sets, special cases that are not
                    162:     (yet) handled, etc.
                    163:
                    164: No bugs have been reported.
                    165:
                    166: Please report any bugs or feature requests to
                    167: C<bug-text-todo-rest-api-text@rt.cpan.org>, or through the web interface at
                    168: L<http://rt.cpan.org>.
                    169:
                    170:
                    171: =head1 AUTHOR
                    172:
                    173: Andrew Fresh  C<< <andrew@cpan.org> >>
                    174:
                    175:
                    176: =head1 LICENSE AND COPYRIGHT
                    177:
                    178: Copyright (c) 2010, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
                    179:
                    180: This module is free software; you can redistribute it and/or
                    181: modify it under the same terms as Perl itself. See L<perlartistic>.
                    182:
                    183:
                    184: =head1 DISCLAIMER OF WARRANTY
                    185:
                    186: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
                    187: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
                    188: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
                    189: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
                    190: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    191: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
                    192: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
                    193: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
                    194: NECESSARY SERVICING, REPAIR, OR CORRECTION.
                    195:
                    196: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                    197: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
                    198: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
                    199: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
                    200: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
                    201: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
                    202: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
                    203: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
                    204: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                    205: SUCH DAMAGES.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>