AnyEvent-MP
view release on metacpan or search on metacpan
MP/Config.pm view on Meta::CPAN
our $CONFIG_FILE = exists $ENV{PERL_ANYEVENT_MP_RC} ? $ENV{PERL_ANYEVENT_MP_RC}
: exists $ENV{HOME} ? "$ENV{HOME}/.perl-anyevent-mp"
: "$ENV{APPDATA}/perl-anyevent-mp";
our %CFG;
sub load {
if (open my $fh, "<:raw", $CONFIG_FILE) {
return if eval {
local $/;
%CFG = %{ JSON::XS->new->utf8->relaxed->decode (scalar <$fh>) };
1
};
}
%CFG = (
version => 1,
);
}
sub save {
return unless delete $CFG{dirty};
open my $fh, ">:raw", "$CONFIG_FILE~new~"
or Carp::croak "$CONFIG_FILE~new~: $!";
syswrite $fh, JSON::XS->new->pretty->utf8->encode (\%CFG) . "\n"
or Carp::croak "$CONFIG_FILE~new~: $!";
close $fh
or Carp::croak "$CONFIG_FILE~new~: $!";
unlink "$CONFIG_FILE~";
link $CONFIG_FILE, "$CONFIG_FILE~";
rename "$CONFIG_FILE~new~", $CONFIG_FILE
or Carp::croak "$CONFIG_FILE: $!";
}
MP/Kernel.pm view on Meta::CPAN
$NODE_REQ{g_slave} = sub {
# load global module and redo the request
require AnyEvent::MP::Global;
&{ $NODE_REQ{g_slave} }
};
#############################################################################
# local database operations
# canonical probably not needed
our $sv_eq_coder = JSON::XS->new->utf8->allow_nonref;
# are the two scalars equal? very very ugly and slow, need better way
sub sv_eq($$) {
ref $_[0] || ref $_[1]
? (JSON::XS::encode $sv_eq_coder, $_[0]) eq (JSON::XS::encode $sv_eq_coder, $_[1])
: $_[0] eq $_[1]
&& defined $_[0] == defined $_[1]
}
# local database management
MP/Transport.pm view on Meta::CPAN
$hdl->on_read (sub {
$AnyEvent::MP::Kernel::SRCNODE = $node;
AnyEvent::MP::Kernel::_inject (@$_)
for $coder->incr_parse_multiple ($_[0]{rbuf});
()
});
} elsif ($framing eq "json") {
require JSON::XS;
my $coder = JSON::XS->new->utf8;
$hdl->on_read (sub {
$AnyEvent::MP::Kernel::SRCNODE = $node;
AnyEvent::MP::Kernel::_inject (@$_)
for $coder->incr_parse (delete $_[0]{rbuf});
()
});
} else {
=cut
use common::sense;
# should come before anything else, so all modules
# will be loaded on each restart
BEGIN {
if (@ARGV == 1 && $ARGV[0] =~ /^\[/) {
require JSON::XS;
@ARGV = @{ JSON::XS->new->utf8->decode (shift) };
} else {
for (@ARGV) {
if (/^[\[\{\"]/) {
require JSON::XS;
$_ = JSON::XS->new->utf8->allow_nonref->decode ($_);
}
}
}
if ($ARGV[0] eq "run") {
shift;
# d'oh
require AnyEvent::Watchdog;
# only now can we load additional modules
( run in 0.619 second using v1.01-cache-2.11-cpan-49f99fa48dc )