Bot-Cobalt

 view release on metacpan or  search on metacpan

lib/Bot/Cobalt/DB.pm  view on Meta::CPAN

  isa       => Bool,
  builder   => sub { 0 },
);
{ no warnings 'once'; *Raw = *raw; }

has timeout => (
  is        => 'rw',
  isa       => Num,
  builder   => sub { 5 },
);
{ no warnings 'once'; *Timeout = *timeout; }

has serializer => (
  lazy      => 1,
  is        => 'rw',
  isa       => Object,
  builder   => sub {
    Bot::Cobalt::Serializer->new(Format => 'JSON')
  },
);
{ no warnings 'once'; *Serializer = *serializer; }

lib/Bot/Cobalt/DB.pm  view on Meta::CPAN


sub BUILDARGS {
  my ($class, @args) = @_;
  return +{ file => $args[0] } if @args == 1;
  # Back-compat and I hate myself
  my %opt = @args;
  my $lower = array( qw/
    File
    Perms
    Raw
    Timeout
    Serializer
    Tied
  / );
  for my $key (%opt) {
    if ( $lower->has_any(sub { $_ eq $key }) ) {
      my $val = delete $opt{$key};
      $opt{lc $key} = $val
    }
  }
  \%opt

lib/Bot/Cobalt/Plugin/WWW.pm  view on Meta::CPAN


sub bindaddr {
  $_[0]->opts->{BindAddr}
}

sub proxy {
  $_[0]->opts->{Proxy}
}

sub timeout {
  $_[0]->opts->{Timeout}    || 90
}

sub max_per_host {
  $_[0]->opts->{MaxPerHost} || 5
}

sub max_workers {
  $_[0]->opts->{MaxWorkers} || 25
}

lib/Bot/Cobalt/Plugin/WWW.pm  view on Meta::CPAN


sub _start {
  my ($self, $kernel) = @_[OBJECT, KERNEL];

  my $sess_alias = 'www_'. core()->get_plugin_alias($self);
  $kernel->alias_set( $sess_alias );

  my %opts;
  $opts{BindAddr} = $self->bindaddr if $self->bindaddr;
  $opts{Proxy}    = $self->proxy    if $self->proxy;
  $opts{Timeout}  = $self->timeout;

  ## Create "ht_${plugin_alias}" session
  POE::Component::Client::HTTP->spawn(

    FollowRedirects => 5,

    Agent => __PACKAGE__,

    Alias => 'ht_'. core()->get_plugin_alias($self),

lib/Bot/Cobalt/Serializer.pm  view on Meta::CPAN


sub _write_serialized {
  my ($self, $path, $data, $opts) = @_;
  return unless $path and defined $data;

  my $lock    = 1;
  my $timeout = 2;

  if (defined $opts && ref $opts && reftype $opts eq 'HASH') {
    $lock    = $opts->{Locking} if defined $opts->{Locking};
    $timeout = $opts->{Timeout} if $opts->{Timeout};
  }

  open(my $out_fh, '>>:encoding(UTF-8)', $path)
    or confess "open failed for $path: $!";

  if ($lock) {
    my $timer = 0;

    until ( flock $out_fh, LOCK_EX | LOCK_NB ) {
      confess "Failed writefile lock ($path), timed out ($timeout)"

lib/Bot/Cobalt/Serializer.pm  view on Meta::CPAN

written to disk due to an error.

Locks the file by default; blocks for up to 2 seconds attempting to 
gain a lock. You can turn this behavior off entirely:

  $serializer->writefile($path, $ref, { Locking => 0 });

... or change the lock timeout (defaults to 2 seconds):

  $serializer->writefile($path, $ref,
    { Locking => 1, Timeout => 5 }
  );


=head2 readfile

Read the serialized file at the specified C<$path> (if possible) and 
L</thaw> the data structures back into a reference.

  my $ref = $serializer->readfile($path);

share/etc/plugins/www.conf  view on Meta::CPAN


  ## A local IP to bind to for outgoing connections.
  ## (Default uses INADDR_ANY)
  BindAddr: ~

  ## A HTTP proxy to use, in the form of ADDRESS:PORT
  ##  f.ex some.http.proxy:8080
  Proxy: ~

  ## HTTP request timeout. Defaults to 90 seconds.
  Timeout: 90



( run in 0.443 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )