include:
- XML (via XML::Simple)
- XML+XSLT
- Data::Dumper
- Javascript, Javascript::Anon & JSON
- UrlEncoded
- The formats supported by Data::Serializer (e.g. Config::General and Config::Wres
========
sub get_converter # ($function)
{
my $convert = ($_[0] =~ s/:JSON$//
? 'WebService::NFSN::decode_json'
: '');
return $convert;
} # end get_converter
#-
encode decode/;
use LWP::UserAgent;
use HTML::TreeBuilder;
use HTML::Element;
use XML::Smart;
use JSON;
use YAML qw(Dump);
use utf8;
use Carp;
my %area_zh = (
'台北市' => '36_01_data.htm'
my $weather = Weather::TW->new;
my $xml = $weather->area('Taipei City')->xml;
my $json = $weather->json;
my $yaml = $weather->yaml;
my %hash = $weather->hash;
foreach my $area (
PTION
This module parse data from L<http://www.cwb.gov.tw/> (中央氣象局), and generates xml/json/hash/yaml data.
=head1 OLD METHODS
=over
=item C<< new >>
Create a new C<Weather::TW> object.
WWW::DataWiki::FMT_NT, 0.6, 'text/plain', undef, 'utf-8'],
[WWW::DataWiki::FMT_JSON, 0.6, 'application/json', undef, 'utf-8'],
[WWW::DataWiki::FMT_XML, 0.6, 'application/rdf+xml',
ation/rdf+xml',
'.xhtml'=> 'application/xhtml+xml',
'.html' => 'text/html',
'.json' => 'application/json',
};
}
method rdf_string_conforms_to ($format)
{
return 1 if $format eq WWW::
'application/sparql-results+xml', undef, 'utf-8'],
[WWW::DataWiki::FMT_RS_JSON, 0.9, 'application/x-sparql-results+json', undef, 'utf-8'],
[WWW::DataWiki::FMT_RS_TEXT, 0.6, 'text/plain', undef
s+xml',
'.xhtml'=> 'application/xhtml+xml',
'.html' => 'text/html',
'.json' => 'application/x-sparql-results+json',
'.txt' => 'text/plain',
'.csv' => 'text/csv',
'.tab' => 'text/t
s_string_as ($fmt)
{
my $str;
given ($fmt)
{
when (WWW::DataWiki::FMT_RS_JSON) { $str = $self->rs->as_json; }
when (WWW::DataWiki::FMT_RS_XML) { $str = $self->rs->as_xml; }
when (WW
e; charset=utf-8',
'rdf' => 'application/rdf+xml; charset=utf-8',
'json' => 'application/json',
}->{$variant} || 'application/octet-stream';
$headers{'Content-Typ
xml/i) { $parser = RDF::Trine::Parser::RDFXML->new; }
when (/json/i) { $parser = RDF::Trine::Parser::RDFJSON->new; }
when (/text.plain/i) { $parser = RDF::Trine::Parser::NTrip
Triples), application/xhtml+xml (i.e. XHTML+RDFa 1.0), application/rdf+xml and application/json (i.e. RDF/JSON).');
}
}
# Check it's syntactically sound
my $model;
if (
-9-]*[a-z0-9])(?:/[a-z][a-z0-9-]*[a-z0-9])*)';
our $RE_ext = '(\.nt|\.n3|\.ttl|\.x?html|\.xml|\.json|\.txt|\.csv|\.tab)';
our $RE_path = "${RE_page}${RE_ext}?";
our $RE_vid = '(\d{4}(?:\d{2}(?:\d
plication/sparql-update, text/n3, text/turtle, text/plain, application/rdf+xml;q=0.5, application/json;q=0.1, application/xhtml+xml;q=0.1, text/html;q=0.1'});
}
}
action wikipage_PATCH
{
my ($
s.',
{'X-Accept' => 'text/n3, text/turtle, text/plain, application/rdf+xml;q=0.5, application/json;q=0.1, application/xhtml+xml;q=0.1, text/html;q=0.1'});
}
}
action wikipage_DELETE
{
my (
ey are optimised for serialisation, see
L<Data::MultiValued::UglySerializationHelperRole> and F<t/json.t>.
=item *
you get accessors generated for your Moose attributes just by setting
a trait
=ite
package Acme::JWT;
use strict;
use warnings;
our $VERSION = '0.04';
use JSON qw/decode_json encode_json/;
use MIME::Base64 qw/encode_base64url decode_base64url/;
use Try::Tiny;
use Digest::SHA qw/hma
=> $algorithm,
};
push(@$segments, encode_base64url(encode_json($header)));
push(@$segments, encode_base64url(encode_json($payload)));
my $signing_input = join('.', @$segments);
un
$payload;
my $signature;
try {
$header = decode_json(decode_base64url($header_segment));
$payload = decode_json(decode_base64url($payload_segment));
$signature = decod
FMT_XHTML => 'XHTML',
FMT_HTML => 'HTML',
FMT_JSON => 'RDFJSON',
};
use constant {
FMT_RS_XML => 'xml',
FMT_RS_JSON => 'json',
FMT_RS_TEXT => 'txt',
FMT_RS_HTML => 'html',
point. HTTP content negotiation serves up graph data as HTML, Turtle,
RDF/XML, JSON; and query results as HTML, XML, JSON, CSV or tab-delimited data.
WWW::DataWiki is fully RESTful, using HTTP B<GET>
>uri, 'n3'), ')',
' (', a(-rel=>'rel:alternate', -href=>$ver->formatted_page_iri('json')->uri, 'json'), ')',
br(
-property => 'awol:published',
-content => $publ
html\+xml}i;
return WWW::DataWiki->FMT_JSON if $format =~ m{^(RDF[\s_/-]?)?JSON}i;
return WWW::DataWiki->FMT_JSON if $format =~ m{^application/json}i;
return WWW::DataWiki->FMT_XML if
tt',
);
Later:
my $json = JSON::XS->new->utf8;
my $obj = My::Class->new(rr=>'foo');
my $str = $json->encode($obj->as_hash);
my $obj2 = My::Class->new_in_place($json->decode($str));
# $
package Net::ZooTool::Utils;
use Moose::Role;
use JSON::XS;
use Carp;
use Data::Dumper;
use Digest::SHA1 qw/sha1_hex/;
use WWW::Curl::Easy;
use namespace::autoclean;
our $VERSION = '0.003';
=head
URLINFO_HTTP_CODE);
# judge result and next action based on $response_code
return JSON::XS->new->utf8->decode($response_body);
}
else {
carp( "An error happened: $ret
pplication/sparql-query, text/n3, text/turtle, text/plain, application/rdf+xml;q=0.5, application/json;q=0.1, application/xhtml+xml;q=0.1, text/html;q=0.1'});
}
}
action container_OPTIONS
{
my
any type of file supported by L<Config::Any|Config::Any>: Apache config style (Config::General), JSON, INI files, XML, YAML or perl code.
Here is an example of a configuration file that uses L<Confi
package AnyEvent::JSONRPC::Lite::Server;
use Any::Moose;
use Carp;
use Scalar::Util 'weaken';
use AnyEvent::Handle;
use AnyEvent::Socket;
use AnyEvent::JSONRPC::Lite::CondVar;
has address => (
fh => $fh,
);
$handle->on_read(sub {
shift->unshift_read( json => sub {
$self->_dispatch($indicator, @_);
}),
});
$
$type = shift;
my $result = @_ > 1 ? \@_ : $_[0];
$handle->push_write( json => {
id => $id,
result => $type eq 'result' ? $result : undef
use Alice::HTTP::Request;
use Alice::HTTP::Stream::XHR;
use Alice::HTTP::Stream::WebSocket;
use JSON;
use Encode;
use Any::Moose;
has app => (
is => 'ro',
isa => 'Alice',
required => 1,
);
new_server', $name);
my $listitem = $self->render('server_listitem', $name);
$res->body(to_json({config => $config, listitem => $listitem}));
$res->header("Cache-control" => "no-cache");
$r
$self, $req, $res) = @_;
$res->content_type("text/plain; charset=utf-8");
{
$res->body(to_json($self->app->config->serialized,
{utf8 => 1, pretty => 1}));
}
$res->send;
}
__PACKAGE_
package Alice::HTTP::Stream::WebSocket;
use JSON;
use Any::Moose;
use Digest::MD5 qw/md5/;
use Time::HiRes qw/time/;
extends 'Alice::HTTP::Stream';
has fh => (
is => 'ro',
required => 1,
);
ha
$_[0]->push_read(
'AnyEvent::Handle::Message::WebSocket',
sub { $self->on_read->(from_json $_[1]) }
);
});
$self->handle($h);
$self->send([{type => "identify", id => $self->
lf, $messages) = @_;
$messages = [$messages] unless ref $messages eq "ARRAY";
my $line = to_json(
{queue => $messages},
{utf8 => 1, shrink => 1}
);
$self->send_raw($line);
}
sub
ry.)
BEGIN { $| = 1; print "1..3\n"; }
END {print "not ok 1\n" unless $loaded;}
use GD;
use JSON::Parse;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert