Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
Created May 22, 2010 15:03

Revisions

  1. tom-lpsd created this gist May 22, 2010.
    35 changes: 35 additions & 0 deletions tied.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    package Foo;
    use 5.010;
    use strict;
    use warnings;

    sub TIESCALAR {
    my $class = shift;
    bless \(my $init = "initial value"), $class;
    }

    sub FETCH {
    my $self = shift;
    return $$self;
    }

    sub STORE {
    my $self = shift;
    $$self = shift;
    }

    sub foo {
    say "foo";
    }

    package main;
    use 5.010;
    use strict;
    use warnings;

    my $f = tie my $foo, 'Foo';

    say $foo;

    $f->foo;
    (tied $foo)->foo;