The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Lim::Util - Utilities for plugins

VERSION

See Lim for version.

SYNOPSIS

    use Lim::Util;

METHODS

$full_path = Lim::Util::FileExists($file)

Check if $file exists by prefixing Lim::Config->{prefix} and returns the full path to the file or undef if it does not exist.

$full_path = Lim::Util::FileReadable($file)

Check if $file exists by prefixing Lim::Config->{prefix} and if it is readable. Returns the full path to the file or undef if it does not exist.

$full_path = Lim::Util::FileWritable($file)

Check if $file exists by prefixing Lim::Config->{prefix} and if it is writable. Returns the full path to the file or undef if it does not exist.

$content = Lim::Util::FileReadContent($file)

Read the file and return the content or undef if there was an error.

[$temp_file] = Lim::Util::FileWriteContent([$file | $object,] $content)

Write the content to a file or a new temporary file, content in file will be reread and checked with a SHA checksum.

If the $file is specified, write the content to the filename and return 1 or undef on error. Will overwrite the file if it exists.

If the $object is a Temp::File object, write the content to that file and return 1 or undef on error.

If no $file or $object is specified, write the content to a new temporary file and return the File::Temp object or undef on error.

$temp_file = Lim::Util::TempFile

Creates a temporary file. Returns a File::Temp object or undef if there where problems creating the temporary file.

$temp_file = Lim::Util::TempFileLikeThis($file)

Creates a temporary file that will have the same owner and mode as the specified $file. Returns a File::Temp object or undef if the specified file did not exist or if there where problems creating the temporary file.

($method, $uri) = Lim::Util::URIize($call)

Returns an URI based on the $call given and the corresponding HTTP method to be used.

Example:

    use Lim::Util; ($method, $uri) = Lim::Util::URIize('ReadVersion'); print "$method $ur\n"; ($method, $uri) = Lim::Util::URIize('CreateOtherCall'); print "$method $ur\n";

Produces:

    GET /version PUT /other_call

$hash_ref = Lim::Util::QueryDecode($query_string)

Returns an HASH reference of the decode query string.

$camelized = Lim::Util::Camelize($underscore)

Convert underscored text to camelized, used for translating URI to calls.

Example:

    use Lim::Util; print Lim::Util::Camelize('long_u_r_i_call_name'), "\n";

Produces:

    LongURICallName

[$cv =] Lim::Util::run_cmd $cmd, key => value...

This function extends AnyEvent::Util::run_cmd with a timeout and will also set close_all option.

timeout => $seconds

Creates a timeout for the running command and will try and kill it after the specified $seconds, see below how you can change the kill functionallity.

Using timeout will set $$ option to AnyEvent::Util::run_cmd so you won't be able to use that option.

cb => $callback->($cv)

This is required if you'r using timeout.

Call the given $callback when the command finish or have timed out with the condition variable returned by AnyEvent::Util::run_cmd. If the command timed out the condition variable will be set as if the command failed.

kill_sig => 15

Signal to use when trying to kill the command.

kill_try => 3

Number of times to try and kill the command with kill_sig.

interval => 1

Number of seconds to wait between each attempt to kill the command.

kill_kill => 1

If true (default) kill the command with signal KILL after trying to kill it with kill_sig for the specified number of kill_try attempts.

AUTHOR

Jerry Lundström, <lundstrom.jerry at gmail.com>

BUGS

Please report any bugs or feature requests to https://github.com/jelu/lim/issues.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Lim::Util

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012-2013 Jerry Lundström.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.