1
# This program is copyright 2012-2013 Percona Inc.
2
# Feedback and improvements are welcome.
4
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
5
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
6
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
8
# This program is free software; you can redistribute it and/or modify it under
9
# the terms of the GNU General Public License as published by the Free Software
10
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
11
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16
# Place, Suite 330, Boston, MA 02111-1307 USA.
17
# ###########################################################################
18
# Percona::WebAPI::Representation package
19
# ###########################################################################
21
package Percona::WebAPI::Representation;
28
our @ISA = qw(Exporter);
36
my ($resource, %args) = @_;
38
# Copy the object into a new hashref.
39
my $as_hashref = { %$resource };
41
# Delete the links because they're just for client-side use
42
# and the caller should be sending this object, not getting it.
43
# But sometimes for testing we want to keep the links.
44
if ( !defined $args{with_links} || !$args{with_links} ) {
45
delete $as_hashref->{links};
52
my ($resource, %args) = @_;
54
my $json = $args{json} || JSON->new;
55
$json->allow_blessed([]);
56
$json->convert_blessed([]);
58
my $text = $json->encode(
59
ref $resource eq 'ARRAY' ? $resource : as_hashref($resource, %args)
61
if ( $args{json} && $text ) { # for testing
70
if ( !$resource->isa('Percona::WebAPI::Resource::Config') ) {
71
die "Only Config resources can be represented as config.\n";
73
my $as_hashref = as_hashref($resource);
74
my $options = $as_hashref->{options};
75
my $config = join("\n",
76
map { defined $options->{$_} ? "$_=$options->{$_}" : "$_" }
84
# ###########################################################################
85
# End Percona::WebAPI::Representation package
86
# ###########################################################################