Catmandu
view release on metacpan or search on metacpan
lib/Catmandu/Util.pm view on Meta::CPAN
use Catmandu::Util qw(:human);
=over 4
=item human_number($num)
Insert a comma a 3-digit intervals to make C<$num> more readable. Only works
with I<integers> for now.
human_number(64354);
# => "64,354"
=item human_byte_size($size)
human_byte_size(64);
# => "64 bytes"
human_byte_size(10005000);
# => "10.01 MB"
=item human_content_type($content_type)
=item human_content_type($content_type, $default)
human_content_type('application/x-dos_ms_excel');
# => "Excel"
human_content_type('application/zip');
# => "ZIP archive"
human_content_type('foo/x-unknown');
# => "foo/x-unknown"
human_content_type('foo/x-unknown', 'Unknown');
# => "Unknown"
=back
=head2 XML functions
use Catmandu::Util qw(:xml);
=over 4
=item xml_declaration()
Returns C<< qq(<?xml version="1.0" encoding="UTF-8"?>\n) >>.
=item xml_escape($str)
Returns an XML escaped copy of C<$str>.
=back
=head2 Miscellaneous functions
=over 4
=item require_package($pkg)
=item require_package($pkg, $namespace)
Load package C<$pkg> at runtime with C<require> and return it's full name.
my $pkg = require_package('File::Spec');
my $dir = $pkg->tmpdir();
require_package('Util', 'Catmandu');
# => "Catmandu::Util"
require_package('Catmandu::Util', 'Catmandu');
# => "Catmandu::Util"
Throws a Catmandu::Error on failure.
=item use_lib(@dirs)
Add directories to C<@INC> at runtime.
Throws a Catmandu::Error on failure.
=item pod_section($package_or_file, $section [, @options] )
Get documentation of a package for a selected section. Additional options are
passed to L<Pod::Usage>.
=item now($format)
Returns the current datetime as a string. C<$format>can be any
C<strftime> format. There are also 2 builtin formats, C<iso_date_time>
and C<iso_date_time_millis>. C<iso_date_time> is equivalent to
C<%Y-%m-%dT%H:%M:%SZ>. C<iso_date_time_millis> is the same, but with
added milliseconds.
now('%Y/%m/%d');
now('iso_date_time_millis');
The default format is C<iso_date_time>;
=back
=cut
( run in 2.419 seconds using v1.01-cache-2.11-cpan-98e64b0badf )