1#!/usr/bin/perl 2# 3# $Header: /Users/claude/fuzz/lib/Genezzo/BufCa/RCS/PinScalar.pm,v 7.1 2005/07/19 07:49:03 claude Exp claude $ 4# 5# copyright (c) 2003, 2004 Jeffrey I Cohen, all rights reserved, worldwide 6# 7# 8use strict; 9use warnings; 10 11package Genezzo::BufCa::PinScalar; 12 13#use Genezzo::Util; 14use Tie::Scalar; 15#use Carp; 16#use warnings::register; 17 18our @ISA = qw(Tie::StdScalar) ; 19 20sub TIESCALAR { 21 my $class = shift; 22 my $instance = shift || undef; 23 # XXX: could use an array for efficiency 24 # [0] for the ref, [1] for the callback 25 my $self = {}; 26 $self->{ref} = \$instance; 27 28 my ($pkg, $fnam, $lin) = caller(1); 29 $self->{package} = $pkg; 30 $self->{filename} = $fnam; 31 $self->{lineno} = $lin; 32 33 return bless $self, $class; 34} 35 36sub FETCH { 37# whoami; 38 return ${$_[0]->{ref}}; 39} 40 41sub STORE { 42# whoami; 43 44 ${$_[0]->{ref}} = $_[1]; 45} 46 47sub DESTROY { 48# whoami; 49 if (defined($_[0]->{destroycb})) 50 { 51 $_[0]->{destroycb}->($_[0]); 52 my ($pkg, $fnam, $lin) = caller(1); 53# whisper "destroyed at $pkg, $fnam, $lin\n"; 54 55 } 56 $_[0]->{ref} = (); 57} 58 59# supply a callback/closure to activate during DESTROY 60sub _DestroyCB 61{ 62# whoami; 63 my $self = shift; 64 $self->{destroycb} = shift if @_ ; 65 return $self->{destroycb}; 66} 67 681; 69 70__END__ 71 72# Below is stub documentation for your module. You better edit it! 73 74=head1 NAME 75 76Genezzo::BufCa::PinScalar - detect destruction of scalar 77 78=head1 SYNOPSIS 79 80=head1 DESCRIPTION 81 82=head1 ARGUMENTS 83 84=head1 FUNCTIONS 85 86=head2 EXPORT 87 88=head1 LIMITATIONS 89 90various 91 92=head1 #TODO 93 94=over 4 95 96=back 97 98=head1 AUTHOR 99 100Jeffrey I. Cohen, jcohen@genezzo.com 101 102=head1 SEE ALSO 103 104L<perl(1)>. 105 106Copyright (c) 2003, 2004 Jeffrey I Cohen. All rights reserved. 107 108 This program is free software; you can redistribute it and/or modify 109 it under the terms of the GNU General Public License as published by 110 the Free Software Foundation; either version 2 of the License, or 111 any later version. 112 113 This program is distributed in the hope that it will be useful, 114 but WITHOUT ANY WARRANTY; without even the implied warranty of 115 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 116 GNU General Public License for more details. 117 118 You should have received a copy of the GNU General Public License 119 along with this program; if not, write to the Free Software 120 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 121 122Address bug reports and comments to: jcohen@genezzo.com 123 124For more information, please visit the Genezzo homepage 125at L<http://www.genezzo.com> 126 127=cut 128