Scalar::Footnote

652 views

Published on

A quick overview of Scalar::Footnote, the Perl module available here:

http://search.cpan.org/dist/Scalar-Footnote/

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
652
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Talk about history here
  • Scalar::Footnote

    1. 1. Scalar::Footnote A lightening talk by Steve Purkis July 2007
    2. 2. Scalar::Footnote The Idea Some Beer Under the hood in 30s Questions
    3. 3. The Idea <ul><li>Boy , you think, </li></ul><ul><li>Wouldn’t it be great if I could hide stuff from myself so I didn’t have to look at it? </li></ul>Well, now you can.
    4. 4. The Idea <ul><li>Scalar::Footnote lets you attach hidden scalars to references </li></ul><ul><li>So you don’t have to look at them </li></ul><ul><li>No, it doesn’t cat them to /dev/null </li></ul><ul><li>(that wouldn’t be very portable anyway) </li></ul><ul><li>It tucks them away where no-one can see them </li></ul><ul><li>Using magic. </li></ul>
    5. 5. Synopsis <ul><li>use Scalar::Footnote; </li></ul><ul><li>my $obj = bless {}, 'Foo'; </li></ul><ul><li># attach invisible footnote to $obj: </li></ul><ul><li>$obj->Scalar::Footnote::set( my_key => ’my footnote' ); </li></ul><ul><li># get it back: </li></ul><ul><li>$obj->Scalar::Footnote::get( 'my_key' ); </li></ul><ul><li># remove it: </li></ul><ul><li>$obj->Scalar::Footnote::remove( 'my_key' ); </li></ul>
    6. 6. As usual… <ul><li>It’s on CPAN </li></ul><ul><li>It’s been tested </li></ul><ul><li>If you’ve any problems let me know </li></ul>
    7. 7. And really… <ul><li>It’s not that useless </li></ul><ul><li>No, really . </li></ul><ul><li>It’s actually quite useful! </li></ul><ul><li>Ok, so it’s M. Friebe’s idea, not mine. </li></ul><ul><li>(and maybe a little bit of Piers’) </li></ul>
    8. 8. Scalar::Footnote The Idea Some Beer Under the hood in 30s Questions
    9. 9. Some Beer <ul><li>Sorry folks… </li></ul><ul><li>(but ask Mark about the beer ;-) </li></ul>A Quick Example
    10. 10. A Quick Example <ul><li>use Data::Dumper; </li></ul><ul><li>use Scalar::Footnote; </li></ul><ul><li>my $obj = bless [qw( foo bar)], 'Foo'; </li></ul><ul><li>$obj->Scalar::Footnote::set( Foo => 'foo note' ); </li></ul><ul><li>print Dumper( $obj ); </li></ul><ul><li>print 'footnote: ' . $obj->Scalar::Footnote::get( 'Foo' ); </li></ul>Prints: $VAR1 = bless( [ 'foo', 'bar' ], 'Foo' ); footnote: foo note
    11. 11. Plays nicely <ul><li>Keys => don’t overwrite </li></ul><ul><li>Refcounted => destroyed as expected </li></ul><ul><li>Pretty much any kind of scalar </li></ul><ul><li>Pretty much any kind of ref </li></ul>
    12. 12. Doesn’t like Clone.pm :-/ <ul><li>Attempts to clone objects using Clone.pm die: </li></ul><ul><li>Don't know how to handle magic of type 37777777633 at ... </li></ul><ul><li>(Other things that use perl’s internals to clone SV’s will croak too.) </li></ul>
    13. 13. Scalar::Footnote The Idea Some Beer Under the hood in 30s Questions
    14. 14. Under the hood in < 1 min <ul><li>So how’s it work? </li></ul><ul><li>Well, it’s pretty simple actually… </li></ul>
    15. 15. Under the hood in < 1 min <ul><li>You take a $ref, and a $footnote </li></ul><ul><li>Then you write some XS to attach a bit of ‘footnote’ magic to the ref… </li></ul><ul><li>And a bit more to stick a copy of the footnote in the magic </li></ul><ul><li>and presto! </li></ul>SvRV Sv Sv (footnote) Footnote Magic SvPVMG $ref $footnote Sv $footnote (copy)
    16. 16. Scalar::Footnote The Idea Some Beer Under the hood in 30s Questions
    17. 17. Questions?

    ×