[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.4

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

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