Passing results from sub class of html::parser



I'm trying to sub class HTML::Parser and store the parsed result in a
variable so I can access it again from outside the sub class. In the
code below the "text" method would print $text AND if I would say
"$vars->{'text_output'} = "test text";" it would also show "test
text" when calling "print $parser->getTextOutput();" but it will not
print the $text when saying "$vars->{'text_output'} = $text;"

What am I doing wrong here?

package MyParser;
use base qw(HTML::Parser);

my %vars = (
text_output => undef
);

sub text {
my ($self, $text) = @_;
$vars->{'text_output'} = $text;
}

sub getTextOutput {
return $vars->{'text_output'};
}

package main;
use LWP::Simple;

my $parser = MyParser->new;

my $url = @ARGV[0];

my $html = get $url; die "Couldn't get $url" unless defined $html;

$parser->parse( $html );
$parser->eof;
print $parser->getTextOutput();

.