The problem is that when you have a reference, $foo, that points back to some other data structure, such as @bar or %blat, you can only affect that original data structure by dereferencing $foo:
@bar = qw( one small step for man ); $foo = \@bar; $foo->[1] = "big"; print "@bar"; # one big step for man
If, instead, you re-assign to $foo, you've overwritten the fact that $foo is a reference:
@bar = qw( one small step for man ); $foo = \@bar; $foo = [qw( one big step for man )]; print "@bar"; # one small step for man
So, in your second function, even though $hash is a reference to the hash you're passing the function, you then overwrite that variable entirely, destroying the reference (but certainly not the underlying data). Your module's function should take a reference as an argument:
sub tie_session { my ($hash) = @_; eval { tie %$hash, 'Apache::Session::File', undef, { Directory => $r->dir_config('Blah'), LockDirectory => $r->dir_config('Blah'), }; }; return $@ if $@; return $hash; # not actually necessary, but it returns true }
which would be called like so:
sub function { my ($hash) = @_; MyModule::tie_session($hash); $hash->{auth}->{user} = "jacques"; }

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

In reply to Re: References, hashes, and tie() -- oh my by japhy
in thread References, hashes, and tie() -- oh my by jacques

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.