#!/usr/bin/perl


use Data::Dumper;
use HTML::TokeParser;
use LWP::Simple;
use URI::URL;

my $domain	= "http://www.zoozle.net";

my $doc = get($domain);

# titel
# my @title			= $doc	=~ /<title.*?>(.*?)<\/title>/gis;
# print $title[0];

print _getMetakeys(\$doc, "description" );



sub _getMetakeys(){

	my $PageContentScalarRef	= shift;
	my $GetMetaKeyContent		= shift;

	my @content_lines			= split( "\n", ${$PageContentScalarRef} );  # let's make a gigantic string with all the
	my $single_line				= join( "", @content_lines );				# lines of HTML on one line. Come on, it'll be fun
	
	########
	########
	########

	# <meta name = "name" content = "content" \>
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+name\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*\/>/gi;
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+name\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi;
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi;

#	if ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
#		print "META=$1 und CONTENT=$2\n";
#		return $2 if ( $1 =~ /$GetMetaKeyContent/i );	# gib den inhalt von zb description tag zurück
#	} elsif ( $single_line =~ m/<\s*meta\s+name\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
#		print "META=$1 und CONTENT=$2\n";
#		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
#	} elsif ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
#		print "META=$1 und CONTENT=$2\n";
#		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
#	};

	if ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
		print "META=$1 und CONTENT=$2\n";
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );	# gib den inhalt von zb description tag zurück
	} elsif ( $single_line =~ m/<\s*meta\s+name\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
		print "META=$1 und CONTENT=$2\n";
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
	} elsif ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*content\s*=\s*"([^"]+)"\s*>/gi ) {
		print "META=$1 und CONTENT=$2\n";
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
	};

	########
	########
	########

	# <meta name = 'name' content = 'content' \>
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+name\s*=\s*'([^']+)'\s*content\s*=\s*'([^']+)'\s*\/>/gi;
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+name\s*=\s*'([^']+)'\s*content\s*=\s*'([^']+)'\s*>/gi;


	if ( $single_line =~ m/<\s*meta\s+name\s*=\s*'([^']+)'\s*content\s*=\s*'([^']+)'\s*\/>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	} elsif ( $single_line =~ m/<\s*meta\s+name\s*=\s*'([^']+)'\s*content\s*=\s*'([^']+)'\s*>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	};

	########
	########
	########

	# <meta http-equiv = "name" content = "content" \>
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*"([^"]+)"\s*content=\s*"([^"]+)"\s*\/>/gi;
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*"([^"]+)"\s*content=\s*"([^"]+)"\s*>/gi;

	if ( $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*"([^"]+)"\s*content=\s*"([^"]+)"\s*\/>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	} elsif ( $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*"([^"]+)"\s*content=\s*"([^"]+)"\s*>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	};

	########
	########
	########

	# <meta http-equiv = 'name' content = 'content' \>
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*'([^']+)'\s*content=\s*'([^']+)'\s*\/>/gi;
	# $meta{uc($1)} = $2 while $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*'([^']+)'\s*content=\s*'([^']+)'\s*>/gi;

	if ( $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*'([^']+)'\s*content=\s*'([^']+)'\s*\/>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	} elsif ( $single_line =~ m/<\s*meta\s+http-equiv\s*=\s*'([^']+)'\s*content=\s*'([^']+)'\s*>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	};


	########
	########
	########

	# <meta content = "content" name = "name" \>
	# $meta{uc($2)} = $1 while $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*name\s*=\s*"([^"]+)"\s*\/>/gi;
	# $meta{uc($2)} = $1 while $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*name\s*=\s*"([^"]+)"\s*>/gi;
	
	if ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*name\s*=\s*"([^"]+)"\s*\/>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	} elsif ( $single_line =~ m/<\s*meta\s+content\s*=\s*"([^"]+)"\s*name\s*=\s*"([^"]+)"\s*>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	};

	########
	########
	########

	# <meta content = 'content' name = 'name' \>
	# $meta{uc($2)} = $1 while $single_line =~ m/<\s*meta\s+content\s*=\s*'([^']+)'\s*name\s*=\s*'([^']+)'\s*\/>/gi;
	# $meta{uc($2)} = $1 while $single_line =~ m/<\s*meta\s+content\s*=\s*'([^']+)'\s*name\s*=\s*'([^']+)'\s*>/gi;

	if ( $single_line =~ m/<\s*meta\s+content\s*=\s*'([^']+)'\s*name\s*=\s*'([^']+)'\s*\/>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	} elsif ( $single_line =~ m/<\s*meta\s+content\s*=\s*'([^']+)'\s*name\s*=\s*'([^']+)'\s*>/gi ) {
		return $2 if ( $1 =~ /$GetMetaKeyContent/i );
		print "META=$1 und CONTENT=$2\n";
	};

}; # sub get_metakeys() {



exit;

$p = HTML::TokeParser->new( \$doc);

while (my $token = $p->get_tag("a")) {
  my $url = $token->[1]{href} || "-";
  my $text = $p->get_trimmed_text("/a");
  $url = url($url, $base)->abs;
  print "$url\t$text\n";
}