# Copyright 2002 by Marco d'Itri <md@linux.it>
# You can use this software under the terms of the GNU General Public License.

use Irssi;
use Data::Dumper;

use vars qw($VERSION %IRSSI);

$VERSION = '20020128';
%IRSSI = (
	authors		=> 'Marco d\'Itri',
	contact		=> 'md@linux.it',
	name		=> 'dump',
	description	=> 'enable use of Data::Dumper at irssi prompt',
	license		=> 'GPL v2',
	url			=> 'http://www.linux.it/~md/irssi/',
);

Irssi::command_bind('dump' => 'cmd_dump');

sub cmd_dump {
	my ($command, $server, $winit) = @_;

	my (@cmds) = split(/\s+/, $command);
	my @l;
	foreach (@cmds) {
		push @l, dump_var($_);
	}
	foreach (@l) {
		Irssi::print("$_", MSGLEVEL_CRAP);
	}
}

sub dump_var {
	my ($v) = @_;

	my $d = eval "Data::Dumper->new([$v], ['*$v']);";
	if (not $d) {
		Irssi::print("Cannot dump $v");
		return;
	}
	$d->Quotekeys(0);
	$d->Indent(1);
	return split(/\n/, $d->Dump);
}

# Useful things you can dump:
# Irssi::channels()
# Irssi::active_win()
