I'm writing a new module that exports a similar interface to Type::Tie,
but performs a type check on the entire variable each time it is
changed. Obviously, this is much more expensive, but it can be useful
for types like Types::Standard::Dict in cases where speed is not very

In case you're not familiar with Type::Tie, here's a brief summary:
Type::Tie exports a single function, ttie(), which ties variables to
types. For example, after

    use Type::Tie;
    use Types::Standard qw(Num);

    ttie my $num, Num;

setting $num to anything but a number will die. And

    ttie my @num_list, Num;

only allows numbers in @num_list. So

    push @num_list, "foo";

will die.

Type::Tie::Full (the working name for my module) is similar, except that
the entire variable (as a reference) is passed to the type checker. The
sole exception to this is tying scalars--in this case, the referenced
scalar will be passed to the type checker rather than the reference

For example, this works correctly:

    use Type::Tie::Full;
    use Types::Standard qw(Dict Optional Str Num);

    ttie my %dict, Dict[string => Str, number => Optional[Num]],
        string => 'foo';

    $dict{string}       = 'bar';        # ok
    $dict{number}       = 42;           # ok
    $dict{nonexistent}  = 'foo';        # dies
    $dict{number}       = 'foo';        # dies

    delete $dict{string};       # dies ('string' is not optional)
    delete $dict{number};       # ok ('number' is optional)

Currently, only one layer of tying is performed, which means things like
the following don't work how I would like them to:

    use Type::Tie::Full;
    use Types::Standard qw(HashRef Num);

    ttie my $hashref, HashRef[Num], {};

    $hashref = { foo => 'bar' }; # dies ('bar' is not a number)
    $hashref->{foo} = 'bar';     # doesn't die, but probably should

I intend to implement this using deep tying, but it doesn't work for

My question is, does the name make sense for this module? I figure since
it performs a full check on the variable every time it is changed (as
opposed to a check on just the added elements), then it makes sense to
call it that. Would you agree?

And also please let me know if there's anything that should be done
differently or anything like that.

(And yes--the timezone in the Date header of this message is correct. I
need to get on a better sleep schedule!)


I have no doubt that it is a part of the destiny of the human race,
in its gradual improvement, to leave off eating animals.
                -- Thoreau

GPG fingerprint: 38F3 975C D173 4037 B397  8095 D4C9 C4FC 5460 8E68

Attachment: signature.asc
Description: PGP signature

Reply via email to