NAME

Convos::Util - Utility functions

SYNOPSIS

package Convos::Core::Core;
use Convos::Util qw(DEBUG has_many);

DESCRIPTION

Convos::Util is a utily module for Convos.

FUNCTIONS

has_many

has_many $attribute => $related_class => sub {
  my ($self, $attrs) = @_;
  return $related_class->new($attrs);
};

Used to automatically define a create/update, get and list method to the caller class. Example:

has_many users => "Convos::Core::User" => sub {
  my ($self, $attrs) = @_;
  return Convos::Core::User->new($attrs);
};

The definition above results in the following methods:

# Create or update and existing Convos::Core::User object
$user = $class->user(\%attrs);

# Retrieve a Convos::Core::User object or undef()
$user = $class->get_user($id);
$user = $class->get_user(\%attrs);

# Retrieve an array-ref of Convos::Core::User objects
$users = $class->users;

# Remove a user
$user = $class->remove_user($id);
$user = $class->remove_user(\%attrs);

next_tick

$obj = next_tick $obj, sub { my ($obj, @args) = @_ }, @args;

Wrapper around "next_tick" in Mojo::IOLoop.

spurt

$bytes = spurt $bytes => $path;

Write all $bytes at to a temp file, and then replace $path with the temp file. This is almost the same as "spurt" in Mojo::Util, but will not truncate existing files, if the disk is full.

SEE ALSO

Convos.