CGI-Application

 view release on metacpan or  search on metacpan

t/callbacks.t  view on Meta::CPAN

@Event_History = ();

my $app	= My::App->new;
$app->add_callback('prerun', 'my_app_obj_prerun');
$app->run;

my @expected_events	= (
	# init

	'init/CGI::Application::Plugin::Bar::bar_init1',        # CAP::Bar
	'bar_hook/CGI::Application::Plugin::Bar::bar_custom',
	'init/CGI::Application::Plugin::Bar::bar_init2',

	'init/CGI::Application::Plugin::Foo::foo_init1',        # CAP::Foo
	'init/CGI::Application::Plugin::Foo::foo_init2',


	'init/My::Project::my_project_init',                   # My::Project

	'init/My::App::cgiapp_init',                           # My::App (but installed via CGI::Application)

	'init/My::Project::my_project_global_init',            # My::Project (rudely) registered a callback in the
														   # CGI::Application class

	'init/Other::Project::other_project_global_init',      # Other::Project (rudely) registered a callback in the
														   # CGI::Application class, which forces us to	run	it


	# prerun

	'prerun/My::App::my_app_obj_prerun',                   # My::App (installed in object)

	'prerun/CGI::Application::Plugin::Bar::bar_prerun',    # CAP::Foo

	'prerun/My::App::my_app_class_prerun',                 # My::App (but installed at runtime)

	'prerun/CGI::Application::Plugin::Foo::foo_prerun',    # CAP::Bar

	'prerun/My::App::cgiapp_prerun',                       # My::App (but installed via CGI::Application)


	# Run mode
	'runmode/My::App::begin',                              # My::App

	# postrun
	'postrun/CGI::Application::Plugin::Bar::bar_postrun',  # CAP::Bar
	'postrun/CGI::Application::Plugin::Foo::foo_postrun',  # CAP::Foo
	'postrun/My::App::cgiapp_postrun',                     # My::App (but installed via CGI::Application)

	# teardown
	'teardown/My::App::my_app_teardown',                   # My::App (but installed in object)

	'teardown/CGI::Application::Plugin::Bar::bar_teardown',  # CAP::Bar
	'teardown/CGI::Application::Plugin::Foo::foo_teardown',  # CAP::Foo
	'foo_hook/CGI::Application::Plugin::Foo::foo_custom',    # CAP::Foo
	'teardown/My::App::teardown',                            # My::App (but installed via CGI::Application)

);


is_deeply(\@Event_History, \@expected_events, 'My::App - callbacks executed correctly (first run)')
   or do {
		use	Data::Dumper;
		print STDERR "Actual Event History: \n";
		print STDERR Dumper	\@Event_History;
};

# Second run of	My::App	: the callback registered directly in self are
# no longer	installed

@Event_History = ();

My::App->new->run;

@expected_events = (
	# init

	'init/CGI::Application::Plugin::Bar::bar_init1',        # CAP::Bar
	'bar_hook/CGI::Application::Plugin::Bar::bar_custom',
	'init/CGI::Application::Plugin::Bar::bar_init2',

	'init/CGI::Application::Plugin::Foo::foo_init1',        # CAP::Foo
	'init/CGI::Application::Plugin::Foo::foo_init2',


	'init/My::Project::my_project_init',                   # My::Project

	'init/My::App::cgiapp_init',                           # My::App (but installed via CGI::Application)

	'init/My::Project::my_project_global_init',            # My::Project (rudely) registered a callback in the
														   # CGI::Application class

	'init/Other::Project::other_project_global_init',      # Other::Project (rudely) registered a callback in the
														   # CGI::Application class, which forces us to	run	it


	# prerun


	'prerun/CGI::Application::Plugin::Bar::bar_prerun',    # CAP::Foo

	'prerun/My::App::my_app_class_prerun',                 # My::App (but installed at runtime)


	'prerun/CGI::Application::Plugin::Foo::foo_prerun',    # CAP::Bar

	'prerun/My::App::cgiapp_prerun',                       # My::App (but installed via CGI::Application)


	# Run mode
	'runmode/My::App::begin',                              # My::App

	# postrun
	'postrun/CGI::Application::Plugin::Bar::bar_postrun',  # CAP::Bar
	'postrun/CGI::Application::Plugin::Foo::foo_postrun',  # CAP::Foo
	'postrun/My::App::cgiapp_postrun',                     # My::App (but installed via CGI::Application)

	# teardown
	'teardown/My::App::my_app_teardown',                   # My::App (but installed in object)

	'teardown/CGI::Application::Plugin::Bar::bar_teardown',  # CAP::Bar
	'teardown/CGI::Application::Plugin::Foo::foo_teardown',  # CAP::Foo
	'foo_hook/CGI::Application::Plugin::Foo::foo_custom',    # CAP::Foo
	'teardown/My::App::teardown',                            # My::App (but installed via CGI::Application)

);


is_deeply(\@Event_History, \@expected_events, 'My::App - callbacks executed correctly (second run)')
   or do {
		use	Data::Dumper;
		print STDERR "Actual Event History: \n";
		print STDERR Dumper	\@Event_History;
};











@Event_History = ();
Other::App->new->run;

@expected_events = (
	# init

	'init/CGI::Application::Plugin::Bam::bam_init1',        # CAP::Bam
	'init/CGI::Application::Plugin::Bam::bam_init2',

	'init/CGI::Application::Plugin::Baz::baz_init1',        # CAP::Baz
	'init/CGI::Application::Plugin::Baz::baz_init2',


	'init/Other::Project::other_project_init',             # Other::Project

	'init/Other::App::cgiapp_init',                        # Other::App (but installed via CGI::Application)

	'init/My::Project::my_project_global_init',            # My::Project (rudely) registered a callback in the
														   # CGI::Application class, which forces us to	run	it

	'init/Other::Project::other_project_global_init',      # Other::Project (rudely) registered a callback in the
														   # CGI::Application class


	# prerun


	'prerun/CGI::Application::Plugin::Bam::bam_prerun',    # CAP::Baz

	'prerun/CGI::Application::Plugin::Baz::baz_prerun',    # CAP::Bam

	'baz_hook/CGI::Application::Plugin::Baz::baz_custom',  # CAP::Bam


	'prerun/Other::App::cgiapp_prerun',                    # Other::App (but installed via CGI::Application)


	# Run mode
	'runmode/Other::App::begin',                           # Other::App

	# postrun
	'postrun/Other::App::other_app_postrun',               # Other::App (but installed in object)

	'postrun/CGI::Application::Plugin::Bam::bam_postrun',  # CAP::Bam
	'bam_hook/CGI::Application::Plugin::Bam::bam_custom',  # CAP::Bam


	'postrun/CGI::Application::Plugin::Baz::baz_postrun',  # CAP::Baz
	'postrun/Other::App::cgiapp_postrun',                  # Other::App (but installed via CGI::Application)

	# teardown
	'teardown/CGI::Application::Plugin::Bam::bam_teardown',  # CAP::Bam
	'teardown/CGI::Application::Plugin::Baz::baz_teardown',  # CAP::Baz
	'teardown/Other::App::teardown',                         # Other::App (but installed via CGI::Application)

);

is_deeply(\@Event_History, \@expected_events, 'Other::App - callbacks executed correctly')
   or do {
		use	Data::Dumper;
		print STDERR "Actual Event History: \n";
		print STDERR Dumper	\@Event_History;
};


@Event_History = ();
Unrelated::App->new->run;

@expected_events = (
	# init

	'init/Unrelated::App::cgiapp_init',                    # Unrelated::App (but installed via CGI::Application)

	'init/My::Project::my_project_global_init',            # My::Project (rudely) registered a callback in the
														   # CGI::Application class, which forces us to	run	it

	'init/Other::Project::other_project_global_init',      # Unrelated::Project (rudely) registered a callback in the
														   # CGI::Application class, which forces us to	run	it


	# prerun

	'prerun/Unrelated::App::cgiapp_prerun',                # Unrelated::App (but installed via CGI::Application)


	# Run mode
	'runmode/Unrelated::App::begin',                       # Unrelated::App

	# postrun
	'postrun/Unrelated::App::cgiapp_postrun',              # Unrelated::App (but installed via CGI::Application)

	# teardown
	'teardown/Unrelated::App::teardown',                   # Unrelated::App (but installed via CGI::Application)

);

is_deeply(\@Event_History, \@expected_events, 'Unrelated::App - callbacks executed correctly')
   or do {
		use	Data::Dumper;
		print STDERR "Actual Event History: \n";
		print STDERR Dumper	\@Event_History;
};



( run in 0.783 second using v1.01-cache-2.11-cpan-39bf76dae61 )