#!/usr/bin/perl -w use warnings; use strict; package Stupid; { use XML::Twig; sub new { my ( $caller, $args ) = @_; my $class = ref($caller) || $caller; my $self = {}; $self->{a_note} = "This should print something\n"; bless $self, $class; my $code_ref = $self->create_sub; my $t = XML::Twig->new( twig_handlers => { 'a/b' => $code_ref } ); my $xml = "34"; $t->parse($xml); $t->flush; } sub create_sub { my $hidden_self = shift; return sub { my ( $self, $t ) = @_; print ref($self) . "\n"; print ref($t) . "\n"; print $t->text; print "\n\n"; $hidden_self->gah(); }; } sub gah { my $self = shift; print ref($self) . "\n"; print "$self->{a_note}\n"; } }; my $s = Stupid->new();