use strict; use warnings; use Gtk2 -init; MyMain::test(); { package MyMain; sub test{ use Log::Log4perl; Log::Log4perl::init_and_watch( 'logger.conf', 30 ); my $logger = Log::Log4perl->get_logger; # Run main loop. $logger->debug("before gtk"); my $win = Gtk2::Window->new; my $b1= Gtk2::Button->new("test 1"); $b1->signal_connect(clicked => sub{ use subdir::Foo; subdir::Foo::test(); use subdir::Bar; subdir::Bar::test(); use subdir::Baz; subdir::Baz::test(); my $log = Log::Log4perl->get_logger("MyMain"); $log->debug("after get_logger in MyMain ...quit"); Gtk2->main_quit; }); $win->add ($b1); $win->show_all; #main loop Gtk2->main; } 1; }