]> Dogcows Code - chaz/p5-File-KDBX/blobdiff - lib/File/KDBX/Util.pm
convert PerlIO layers to IO handles
[chaz/p5-File-KDBX] / lib / File / KDBX / Util.pm
index 4b4c2c71b9828eecabac99d9153f644f7a6aad24..a074d3e163f2641b5d1936d442a6f7efedefdcc0 100644 (file)
@@ -18,6 +18,7 @@ our $VERSION = '999.999'; # VERSION
 
 our %EXPORT_TAGS = (
     assert      => [qw(assert_64bit)],
+    bool        => [qw(FALSE TRUE)],
     clone       => [qw(clone clone_nomagic)],
     crypt       => [qw(pad_pkcs7)],
     debug       => [qw(dumper)],
@@ -26,7 +27,7 @@ our %EXPORT_TAGS = (
     empty       => [qw(empty nonempty)],
     erase       => [qw(erase erase_scoped)],
     gzip        => [qw(gzip gunzip)],
-    io          => [qw(read_all)],
+    io          => [qw(is_readable is_writable read_all)],
     load        => [qw(load_optional load_xs try_load_optional)],
     search      => [qw(query search simple_expression_query)],
     text        => [qw(snakify trim)],
@@ -424,6 +425,20 @@ sub gzip {
     return $out;
 }
 
+=func is_readable
+
+=func is_writable
+
+    $bool = is_readable($mode);
+    $bool = is_writable($mode);
+
+Determine of an C<fopen>-style mode is readable, writable or both.
+
+=cut
+
+sub is_readable { $_[0] !~ /^[aw]b?$/ }
+sub is_writable { $_[0] !~ /^rb?$/ }
+
 =func is_uuid
 
     $bool = is_uuid($thing);
@@ -805,6 +820,17 @@ sub uuid {
 
 }
 
+=func FALSE
+
+=func TRUE
+
+Constants appropriate for use as return values in functions claiming to return true or false.
+
+=cut
+
+sub FALSE() { !1 }
+sub TRUE()  {  1 }
+
 BEGIN {
     my $use_cowrefcnt = eval { require B::COW; 1 };
     *_USE_COWREFCNT = $use_cowrefcnt ? sub() { 1 } : sub() { 0 };
This page took 0.022473 seconds and 4 git commands to generate.