Skip to content

Commit

Permalink
Documentation tweak (with test) and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
haukex committed Jul 19, 2021
1 parent caa357b commit 15fa3f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/Util/H2O.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Util::H2O - Hash to Object: turns hashrefs into objects with accessors for keys
my $hash = h2o { foo => "bar", x => "y" }, qw/ more keys /;
print $hash->foo, "\n"; # accessor
$hash->x("z"); # change value
$hash->more("quz"); # additional keys
$hash->more("cowbell"); # additional keys
my $struct = { hello => { perl => "world!" } };
h2o -recurse, $struct; # objectify nested hashrefs as well
Expand Down Expand Up @@ -145,7 +145,7 @@ in Perl's symbol table and use memory accordingly.
Whether or not to use L<Hash::Util>'s C<lock_ref_keys> to prevent
modifications to the hash's keyset. Defaults to I<true>.
The C<-nolock> option is provided as a short form of C<< lock=>0 >>.
The C<-nolock> option is provided as a short form of C<< -lock=>0 >>.
Keysets of objects created by the constructor generated by the
C<-new> option are also locked. Versions of this module before
Expand All @@ -159,7 +159,7 @@ Versions of this module as of v0.12 issue a warning on old Perls.
=item C<-nolock>
Short form of the option C<< lock=>0 >>.
Short form of the option C<< -lock=>0 >>.
=item C<-ro>
Expand All @@ -170,7 +170,7 @@ other words, this makes the object and the underlying hash immutable.
You cannot specify any C<@additional_keys> with this option enabled unless you
also use the C<-new> option - the additional keys will then only be useful as
arguments to the constructor. This option can't be used with C<-nolock> or
C<< lock=>0 >>.
C<< -lock=>0 >>.
This option was added in v0.12. Using this option will not work and cause a
warning when used on really old Perls (before v5.8.9), because this
Expand All @@ -183,7 +183,8 @@ functionality was not yet available there.
You must supply a plain (unblessed) hash reference here. Be aware
that this function I<does> modify the original hashref(s) by blessing
it and locking its keyset (the latter can be disabled with the
C<-lock> option).
C<-lock> option), and if you use C<-meth> or C<-classify>, keys whose
values are code references will be removed.
An accessor will be set up for each key in the hash; note that the
keys must of course be valid Perl identifiers for you to be able to
Expand Down
7 changes: 6 additions & 1 deletion t/Util-H2O.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ L<http://perldoc.perl.org/perlartistic.html>.
=cut

use Test::More tests => 190;
use Test::More tests => 191;
use Scalar::Util qw/blessed/;

sub exception (&) { eval { shift->(); 1 } ? undef : ($@ || die) } ## no critic (ProhibitSubroutinePrototypes, RequireFinalReturn, RequireCarping)
Expand Down Expand Up @@ -127,6 +127,11 @@ my $PACKRE = qr/\AUtil::H2O::_[0-9A-Fa-f]+\z/;
is_deeply $o, { x=>111, y=>333 };
is $o->y, 222;
}
{
my $h = { foo => 123, bar => sub {} };
h2o -meth, $h;
is_deeply $h, { foo => 123 };
}

# -class
{
Expand Down
2 changes: 1 addition & 1 deletion xt/author.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ subtest 'code in POD' => sub { plan tests=>9;
ok eval('{'.<<"END_CODE".';1}'), 'synopsis runs' or diag explain $@; ## no critic (ProhibitStringyEval, RequireCheckingReturnValueOfEval)
use warnings; use strict;
$$verbatim[0];
is_deeply \$hash, { foo=>'bar', x=>'z', more=>'quz' }, 'synopsis \$hash';
is_deeply \$hash, { foo=>'bar', x=>'z', more=>'cowbell' }, 'synopsis \$hash';
is_deeply \$struct, { hello => { perl => "world!" } }, 'synopsis \$struct';
isa_ok \$one, 'Point';
is_deeply \$one, { x=>1, y=>2 }, 'synopsis \$one';
Expand Down

0 comments on commit 15fa3f9

Please sign in to comment.