dexer::Output::JSON;
use strict;
use warnings;
use JSON::XS;
require IRC::Indexer::Output;
our @ISA = qw/IRC::Indexer::Output/;
sub dump {
my ($self) = @_;
$self->{Output} = JSON::XS->new->utf8
lf->{Output} = JSON::XS->new->utf8(1)->indent->encode(
$self->{Input}
) . "\n" ;
$self->SUPER::write($path);
}
1;
__END__
=pod
=head1 NAME
IRC::Indexer::Output::JSON - JSON::XS output sub
class
=head1 DESCRIPTION
L<IRC::Indexer::Output> subclass serializing via L<JSON::XS>.
See L<IRC::Indexer::Output> for usage details.
=head1 AUTHOR
Jon Portnoy <avenj@cobaltirc.org>
=cut
ess::JSONify;
## Forking JSON encoder.
## Process refs, encode JSON, return to master and die.
## Pass me a reference:
## ->put([ $json, $network, $server_name ])
## Get back JSON:
## [ $json, $ne
twork, $server_name ]
use strict;
use warnings;
use IRC::Indexer::Output::JSON;
use Storable qw/nfreeze thaw/;
use Compress::Zlib qw/memGzip/;
use bytes;
sub worker {
$0 = "ircindexer ENCODE" u
my $jsify = IRC::Indexer::Output::JSON->new(
Input => $hash,
);
my $json = $jsify->dump;
my $gzipped = memGzip($json);
my $frozen = nfreeze( [ $
here will be some extra processing overhead when results are
## cached.
CacheDir: /home/ircindex/jsoncache
## LogFile:
##
## Path to log file.
## If omitted, no logging takes place.
LogFile: /home/i
rawlers: 10
## MaxEncoders:
##
## Workers are forked off to handle the potentially expensive
## JSON encoding of server trawl results; if you're trawling
## a lot of networks, you may want to throt
Output::JSON;
# or: use IRC::Indexer::Output::YAML;
# or: use IRC::Indexer::Output::Dumper;
## Convert trawler output into JSON, for example:
my $output = IRC::Indexer::Output::JSON->new(
as L<IRC::Indexer::Output::JSON>.
=head1 METHODS
=head2 new
Create an output encoder; the reference to serialize must be specified:
my $out = IRC::Indexer::Output::JSON->new(
Input => $ref,
);
=head2 dump
Return the serialized output as a scalar.
my $json = $out->dump;
=head2 write
Write serialized output to a file path or an opened FH.
$out->write($path);
Will croak() on er
t and session to handle a single forked trawler.
## This is mostly intended for ircindexer-server-json.
## Provide compatible methods w/ Bot::Trawl
## Other layers can use this with the same interfac
he distribution.
=head1 JSON SERVER
L<ircindexer-server-json> can be used to manage a set of trawlers,
exporting JSON over HTTP for use by frontends.
Note that server-json only reports networks &
d storage.
Assuming your ircindexer-server-json is running on port 8700 on
localhost:
=head2 Retrieve available networks
use LWP::UserAgent;
use JSON::XS;
my $response = LWP::UserAgent->n
my $networks;
if ($response->success) {
my $json = $response->content;
$networks = decode_json($json);
} else {
## Retrieving JSON failed ...
## You can check for $response->c
provided by
L<IRC::Indexer::Report::Network>.
Current as of IRC::Indexer 0.01
=head1 FORMAT
B<JSON> is the preferred format for network transmission; it is light
and support is fairly universal.
SIS
## Pull stats from a single server:
$ ircindexer-single -s irc.cobaltirc.org -f JSON -o cobaltirc.json
## Generate some example confs:
$ ircindexer-examplecf -t httpd -o httpd.cf
$ $ED
$ $EDITOR cobaltirc/eris.oppresses.us.server
. . .
## Spawn a httpd serving JSON:
$ ircindexer-server-json -c httpd.cf
## See IRC::Indexer::Trawl::Bot for more on using trawlers from
#
rver-json> serves as a real world example of how to use
the trawler system to index IRC networks; it is usable as-is to trawl
sets of IRC servers belonging to configured networks and serve JSON-seri