Gtk2::Ex::FormFactory::Intro

Gtk2::Ex::FormFactory::Widget
+-Gtk2::Ex::FormFactory::Container
|  +-Gtk2::Ex::FormFactory
|  +-Gtk2::Ex::FormFactory::Expander
|  +-Gtk2::Ex::FormFactory::Form
|  +-Gtk2::Ex::FormFactory::HBox
|  +-Gtk2::Ex::FormFactory::Notebook
|  +-Gtk2::Ex::FormFactory::Table
|  +-Gtk2::Ex::FormFactory::VBox
|  +-Gtk2::Ex::FormFactory::Window
+-Gtk2::Ex::FormFactory::Button
+-Gtk2::Ex::FormFactory::CheckButton
+-Gtk2::Ex::FormFactory::CheckButtonGroup
+-Gtk2::Ex::FormFactory::Combo
+-Gtk2::Ex::FormFactory::DialogButtons
+-Gtk2::Ex::FormFactory::Entry
+-Gtk2::Ex::FormFactory::Expander
+-Gtk2::Ex::FormFactory::ExecFlow
+-Gtk2::Ex::FormFactory::GtkWidget
+-Gtk2::Ex::FormFactory::HPaned
+-Gtk2::Ex::FormFactory::HSeparator
+-Gtk2::Ex::FormFactory::Image
+-Gtk2::Ex::FormFactory::Label
+-Gtk2::Ex::FormFactory::List
+-Gtk2::Ex::FormFactory::Menu
+-Gtk2::Ex::FormFactory::Popup
+-Gtk2::Ex::FormFactory::ProgressBar
+-Gtk2::Ex::FormFactory::RadioButton
+-Gtk2::Ex::FormFactory::TextView
+-Gtk2::Ex::FormFactory::Timestamp
+-Gtk2::Ex::FormFactory::ToggleButton
+-Gtk2::Ex::FormFactory::VPaned
+-Gtk2::Ex::FormFactory::VSeparator
+-Gtk2::Ex::FormFactory::YesNo

Gtk2::Ex::FormFactory::Layout
Gtk2::Ex::FormFactory::Rules
Gtk2::Ex::FormFactory::Context
Gtk2::Ex::FormFactory::Proxy
+-Gtk2::Ex::FormFactory::ProxyBuffered

Gtk2-Ex-FormFactory/tutorial/config.pm

# $Id: config.pm,v 1.1 2005/07/04 13:46:36 joern Exp $

package Music::Config;

use strict;

sub get_dbi_source		{ shift->{dbi_source}			}
sub get_dbi_username		{ shift->{dbi_username}			}
sub get_dbi_password		{ shift->{dbi_password}			}
sub get_dbi_test_message	{ shift->{dbi_test_message}		}

sub set_dbi_source		{ shift->{dbi_source}		= $_[1]	}
sub set_dbi_username		{ shift->{dbi_username}		= $_[1]	}
sub set_dbi_password		{ shift->{dbi_password}		= $_[1]	}
sub set_dbi_test_message	{ shift->{dbi_test_message}	= $_[1]	}

sub get_filename		{ "music.conf" }

sub get_connection_data {
	my $self = shift;
	return ($self->get_dbi_source,
		$self->get_dbi_username,
		$self->get_dbi_password);
}

sub get_db_connection_ok	{ shift->{db_connection_ok}		}
sub set_db_connection_ok	{ shift->{db_connection_ok}	= $_[1]	}

sub new {
	my $class = shift;
	
	my $filename = $class->get_filename;

	my $self;
	if ( -f $filename ) {
		$self = do $filename;
	} else {
		$self = bless {
			db_connection_ok	=> 0,
			dbi_source		=> "dbi:mysql:gtk2ff",
			dbi_username		=> "",
			dbi_password		=> "",
		}, $class;
	}
	
	$Music::Config::instance = $self;
	
	return $self;
	
}

sub test_db_connection {
	my $self = shift;
	require DBI;
	my $dbh = eval { DBI->connect($self->get_connection_data) };
	my $ok = $dbh?1:0;
	$self->set_db_connection_ok($ok);
	$dbh->disconnect if $dbh;
	if ( $ok ) {
		require "model.pm" if $ok;
		$self->set_dbi_test_message("<b>Connection Ok</b>");
	} else {
		$self->set_dbi_test_message("<b>$DBI::errstr</b>");
	}
	return $ok;
}

sub save {
	my $self = shift;
	
	require Data::Dumper;
	require FileHandle;
	
	my $dd = Data::Dumper->new ( [$self], ['self'] );
	$dd->Indent(1);
	my $data = $dd->Dump;

	my $file = $self->get_filename;
	my $fh   = FileHandle->new;

	open ($fh, ">$file") or die "can't write $file";
	print $fh $data;
	close $fh;
	
	1;
}

1;