Sign In/My Account | View Cart  
advertisement
-->




   Print.Print
Email.Email article link
The Perl Cookbook, 2nd Edition (cover)

Perl Recipe of the Day

The following recipe is from Perl Cookbook, 2nd Edition, by Tom Christiansen and Nathan Torkington. All links in this recipe point to the online version of the book on the Safari Bookshelf.

Buy it now, or read it online on the Safari Bookshelf.


21.13. Sharing Information Between Handlers

21.13.3. Discussion

Apache modules communicate with each other using notes (see Recipe 21.11). Apache notes act like a hash attached to a request—one handler stores a value for a key in the hash, so that another handler can read it later. The Perl notes features is also a hash attached to the request object, but it's only for the Perl handlers.

To set a pnote, pass a key and a value to the $r->pnotes method. To retrieve a pnote, pass only the key. You can store complex data structures:

$r->pnotes("Person", { Name => "Nat",
                       Age  => 30,
                       Kids => 2 });
# later
$person = $r->pnotes("Person");

and even objects:

$person = new Person;
$person->name("Nat");
$person->age(30);
$person->kids(2);

$r->pnotes(Person => $person);

# later

$person = $r->pnotes("Person");
# $person is a reference to the same object

View the past week's recipes: Today | Yesterday | 3 days ago | 4 days ago | 5 days ago | 6 days ago | A week ago

Sponsored By: