CGI-Application-Plugin-MessageStack-0.34/0000755000175000001470000000000010504260761020517 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/t/0000755000175000001470000000000010504260761020762 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/t/TestAppTT.pm0000644000175000001470000000335210504260761023153 0ustar jasonwebdev00000000000000package TestAppTT; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use CGI::Application::Plugin::TT 0.09; ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third cleanup ) ] ); $self->tmpl_path( './t' ); $self->tt_include_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } sub second { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', -classification => 'ERROR', ); return "message pushed"; } sub third { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/08-capms_config_ac.t0000644000175000001470000000403710504260761024473 0ustar jasonwebdev00000000000000use Test::More; # The cgiapp adds 1 more test to the mix... ## TEST PLAN ## #* capms_config w/ Automatic Clearing # * cgiapp w/ various configuration runmodes # * first request # - establish session # - call capms_config with -automatic_clearing # - push in some messages # * second request # - pass in session # - check output for message # * third request # - pass in session # - call messages() and compare #FILES: 08-capms_config_ac.t, TestAppConfigAC.pm, output.TMPL use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 7; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppConfigAC; my $testapp = TestAppConfigAC->new(QUERY=>CGI->new()); my $output = $testapp->run(); my $test_name; # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected outputs"; # testing for an array of data here... like( $output, qr/this is a test/, $test_name ); like( $output, qr/this is another test/, $test_name ); like( $output, qr/got your stuff updated/, $test_name ); like( $output, qr/another info/, $test_name ); like( $output, qr/some bad stuff/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; $test_name = "good automatic clearing"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; CGI-Application-Plugin-MessageStack-0.34/t/TestAppClear.pm0000644000175000001470000001176010504260761023654 0ustar jasonwebdev00000000000000package TestAppClear; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* messages # * first request: # - establish session # - push in a few messages # * second request: # - pass in session # - call messages() and compare data structure # * third request: # - pass in session # - call messages() with scope and compare data structure # * fourth request: # - pass in session # - call messages() with classification and compare data structure # * fifth request: # - pass in session # - call messages() with both scope & classification and compare data structure #FILES: 04-messages.t, TestMessages.pm sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth fifth cleanup ) ] ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $session->clear( [ '__CAP_MessageStack_Stack' ] ); # muhahahahaha $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR', ); return "all set"; } sub second { my $self = shift; my $session = $self->session; $self->clear_messages(); my $messages = $self->messages(); my $expectation = [ ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub third { my $self = shift; my $session = $self->session; $self->clear_messages( -scope => 'fourth' ); my $messages = $self->messages(); my $expectation = [ { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fourth { my $self = shift; my $session = $self->session; $self->clear_messages( -classification => 'ERROR' ); my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fifth { my $self = shift; my $session = $self->session; $self->clear_messages( -scope => 'fourth', -classification => 'ERROR' ); my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/t/02-check_output.t0000644000175000001470000000511510504260761024065 0ustar jasonwebdev00000000000000use Test::More; # the cgiapp adds one more to the test # above ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish/check for session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # * fourth request: # - pass in session # - call messages() and compare # - check output for 'succeeded' # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 10; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppOutput; my $testapp = TestAppOutput->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request my $test_name = 'session cookie was setup'; like( $output, qr/Set-Cookie: CGISESSID=\w+/, $test_name ); $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $test_name = "got the session id ($session_id)"; ok( $session_id, $test_name ); $test_name = "message isn't in output"; unlike( $output, qr/this is a test/, $test_name ); $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output"; like( $output, qr/message pushed/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "message is in the output"; like( $output, qr/this is a test/, $test_name ); $test_name = "classification was in place"; like( $output, qr/div class="ERROR"/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "messages weren't automatically cleared"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = 'got the expected output from the cleanup runmode'; like( $output, qr/session deleted/, $test_name ); undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; ok( ! -e $file, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/TestAppOutput.pm0000644000175000001470000000423610504260761024126 0ustar jasonwebdev00000000000000package TestAppOutput; use base 'CGI::Application'; use Test::More; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub second { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', -classification => 'ERROR', ); return "message pushed"; } sub third { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub fourth { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/t/07-template_toolkit.t0000644000175000001470000000430410504260761024754 0ustar jasonwebdev00000000000000use Test::More; ## TEST PLAN ## # same as 02-check_output.t, but using a Template # * cgiapp w/ html-template # * first request: # - establish/check for session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 07-template_toolkit.t, TestAppTT.pm, output.tt use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; BEGIN { eval "use TestAppTT"; plan skip_all => "CGI::Application::Plugin::TT 0.09 required for testing TT integration" if $@; } use CGI; plan tests => 8; my $testapp = TestAppTT->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request my $test_name = 'session cookie was setup'; like( $output, qr/Set-Cookie: CGISESSID=\w+/, $test_name ); $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $test_name = "got the session id ($session_id)"; ok( $session_id, $test_name ); $test_name = "message isn't in output"; unlike( $output, qr/this is a test/, $test_name ); $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output"; like( $output, qr/message pushed/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = "message is in the output"; like( $output, qr/this is a test/, $test_name ); $test_name = "classification was in place"; like( $output, qr/div class="ERROR"/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = 'got the expected output from the cleanup runmode'; like( $output, qr/session deleted/, $test_name ); undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; ok( ! -e $file, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/10-capms_config_no_session.t0000644000175000001470000000231110504260761026251 0ustar jasonwebdev00000000000000use Test::More tests => 5; ## TEST PLAN ## # * capms_config w/ dont_use_session # * cgiapp w/ dont_use_session config # * first request # - push in some messages # - check for no messages # - load_tmpl and check for output # * second request # - load_tmpl and check for no messages in output # FILES: 10-capms_config_no_session.t, TestAppConfigNoSession.pm, output.TMPL use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppConfigNoSession; my $cgiapp; my $output; eval { $cgiapp = TestAppConfigNoSession->new(QUERY=>CGI->new()); $output = $cgiapp->run(); }; my $test_name = "didn't die() w/ no session"; ok( !$@, $test_name ); $test_name = "output has message in it"; like( $output, qr/this is a test/, $test_name ); $test_name = "output has classification in it"; like( $output, qr/ERROR/, $test_name ); my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $cgiapp = TestAppConfigNoSession->new(QUERY=>$query); $output = $cgiapp->run(); $test_name = "output doesn't have message in it"; unlike( $output, qr/this is a test/, $test_name ); $test_name = "output doesn't have classification in it"; unlike( $output, qr/"ERROR"/, $test_name );CGI-Application-Plugin-MessageStack-0.34/t/01-nosession.t0000644000175000001470000000065210504260761023410 0ustar jasonwebdev00000000000000use Test::More tests => 2; use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppNoSession; eval { my $t1_obj = TestAppNoSession->new(QUERY=>CGI->new()); my $t1_output = $t1_obj->run(); }; my $err = $@; my $test_name = "testing for die() since we did't use a session"; ok( $err, $test_name ); $test_name = 'testing for right error message'; ok( $err =~ /No session object!/, $test_name );CGI-Application-Plugin-MessageStack-0.34/t/TestAppConfigAC.pm0000644000175000001470000000614610504260761024241 0ustar jasonwebdev00000000000000package TestAppConfigAC; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* capms_config w/ Automatic Clearing # * cgiapp w/ various configuration runmodes # * first request # - establish session # - call capms_config with -automatic_clearing # - push in some messages # * second request # - pass in session # - check output for message # * third request # - pass in session # - call messages() and compare #FILES: 08-capms_config_ac.t, TestAppConfigAC.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'second', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'second', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'second', -message => 'some bad stuff', -classification => 'ERROR', ); $self->capms_config( -automatic_clearing => 1 ); return "all set"; } sub second { my $self = shift; my $session = $self->session(); my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub third { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/t/06-pop_message.t0000644000175000001470000000524210504260761023677 0ustar jasonwebdev00000000000000use Test::More; # five tests below and then one from the TestAppPop cgiapp ## TEST PLAN ## #* pop_message # * first request: # - establish session # - clear private session var # - push in a few messages # * second request: # - pass in session # - call pop_message() and compare # * recall first request # * third request: # - pass in session # - call pop_message() with scope and compare # * recall first request # * fourth request: # - pass in session # - call pop_message() with classification and compare # * recall first request # * fifth request: # - pass in session # - call pop_message() with scope & classification and compare # * sixth request: # - pass in session # - compare the remaining messages() #FILES: 06-pop_message.t, TestAppPop.pm use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 6; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppPop; my $testapp = TestAppPop->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; my $test_name = "got the expected output (pop'd the last msg)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd the scoped msg)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd the classified message)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fifth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd both the scope & classification message)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'sixth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "the remaining data structure is as expected"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; undef $testapp; CGI-Application-Plugin-MessageStack-0.34/t/output.tt0000644000175000001470000000050110504260761022667 0ustar jasonwebdev00000000000000 cgiapp messagestack output template

hello world

[% FOREACH CAP_Messages %]
[% message %]
[% END %] CGI-Application-Plugin-MessageStack-0.34/t/04-messages.t0000644000175000001470000000461110504260761023201 0ustar jasonwebdev00000000000000use Test::More; # that 8 above -- I'm using Test::More in the TestAppMessages class for the # convenient is_deeply method. So that doubles the number of tests below. ## TEST PLAN ## #* messages # * first request: # - establish session # - push in a few messages # * second request: # - pass in session # - call messages() and compare data structure # * third request: # - pass in session # - call messages() with scope and compare data structure # * fourth request: # - pass in session # - call messages() with classification and compare data structure # * fifth request: # - pass in session # - call messages() with both scope & classification and compare data structure #FILES: 04-messages.t, TestMessages.pm use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 8; use CGI; use TestAppMessages; my $testapp = TestAppMessages->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppMessages->new( QUERY => $query ); $output = $testapp->run; my $test_name = "got the expected output (all messages)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppMessages->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (scoped messages)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppMessages->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (classified messages)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fifth' ); $testapp = TestAppMessages->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (both scope & classification)"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppMessages->new( QUERY => $query ); $output = $testapp->run; undef $testapp; CGI-Application-Plugin-MessageStack-0.34/t/pod-coverage.t0000644000175000001470000000025410504260761023523 0ustar jasonwebdev00000000000000#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); CGI-Application-Plugin-MessageStack-0.34/t/00-load.t0000644000175000001470000000037610504260761022311 0ustar jasonwebdev00000000000000#!perl -T use Test::More tests => 1; use base 'CGI::Application'; BEGIN { use_ok( 'CGI::Application::Plugin::MessageStack' ); } diag( "Testing CGI::Application::Plugin::MessageStack $CGI::Application::Plugin::MessageStack::VERSION, Perl $], $^X" ); CGI-Application-Plugin-MessageStack-0.34/t/TestAppConfigNoSession.pm0000644000175000001470000000210110504260761025661 0ustar jasonwebdev00000000000000package TestAppConfigNoSession; ## TEST PLAN ## # * capms_config w/ dont_use_session # * cgiapp w/ dont_use_session config # * first request # - push in some messages # - check for no messages # - load_tmpl and check for output # * second request # - load_tmpl and check for no messages in output # FILES: 10-capms_config_no_session.t, TestAppConfigNoSession.pm, output.TMPL use base 'CGI::Application'; use CGI::Application::Plugin::MessageStack; sub setup { my $self = shift; $self->run_modes( [ qw( start second ) ] ); $self->tmpl_path( './t' ); $self->capms_config( -dont_use_session => 1 ); } sub start { my $self = shift; $self->push_message( -scope => 'start', -message => 'this is a test', -classification => 'ERROR', ); my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub second { my $self = shift; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } 1;CGI-Application-Plugin-MessageStack-0.34/t/pod.t0000644000175000001470000000021410504260761021726 0ustar jasonwebdev00000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); CGI-Application-Plugin-MessageStack-0.34/t/output.TMPL0000644000175000001470000000060410504260761023020 0ustar jasonwebdev00000000000000 cgiapp messagestack output template

hello world

">
CGI-Application-Plugin-MessageStack-0.34/t/05-clear_messages.t0000644000175000001470000000535210504260761024353 0ustar jasonwebdev00000000000000use Test::More; # that 8 above -- I'm using Test::More in the TestAppMessages class for the # convenient is_deeply method. So that doubles the number of tests below. ## TEST PLAN ## #* messages # * first request: # - establish session # - push in a few messages # * second request: # - pass in session # - call messages() and compare data structure # * third request: # - pass in session # - call messages() with scope and compare data structure # * fourth request: # - pass in session # - call messages() with classification and compare data structure # * fifth request: # - pass in session # - call messages() with both scope & classification and compare data structure #FILES: 04-messages.t, TestMessages.pm use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 8; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppClear; my $testapp = TestAppClear->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppClear->new( QUERY => $query ); $output = $testapp->run; my $test_name = "got the expected output (cleared all messages)"; like( $output, qr/succeeded/, $test_name ); # calling this to reset the messages $testapp = TestAppClear->new(QUERY=>CGI->new()); $output = $testapp->run(); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppClear->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (cleared scoped messages)"; like( $output, qr/succeeded/, $test_name ); # calling this to reset the messages $testapp = TestAppClear->new(QUERY=>CGI->new()); $output = $testapp->run(); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppClear->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (cleared classified messages)"; like( $output, qr/succeeded/, $test_name ); # calling this to reset the messages $testapp = TestAppClear->new(QUERY=>CGI->new()); $output = $testapp->run(); $query->param( -name => 'rm', -value => 'fifth' ); $testapp = TestAppClear->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (cleared both scope & classification)"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppClear->new( QUERY => $query ); $output = $testapp->run; undef $testapp; CGI-Application-Plugin-MessageStack-0.34/t/testplan.txt0000644000175000001470000001153410504260761023361 0ustar jasonwebdev00000000000000Test Plan for CAP-MessageStack * simple loading FILES: 00-load.t * cgiapp w/ html-template * first request - check output for ! message - push an info message to see if we get error (w/ no session) FILES: 01-nosession.t, TestAppNoSession.pm, output.TMPL * cgiapp w/ html-template * first request: - establish session - check output for ! message * second request: - pass in session - push an info message * third request: - pass in session - check output for message - check message for proper classification * fourth request: - pass in session - call messages() and compare - check output for 'succeeded' FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL * cgiapp w/ html-template * same as before, but check scoping: - in 2nd request, scope info message for non-existent runmode - in 3rd request, check for ! message - in 4th request, scope info message for arrayref runmodes - in 5th request, check for message (1st arrayref value) - in 6th request, check for message (2nd arrayref value) - in 7th request, check for ! message FILES: 03-scope.t, TestAppScope.pm, output.TMPL * messages * first request: - establish session - push in a few messages * second request: - pass in session - call messages() and compare data structure * third request: - pass in session - call messages() with scope and compare data structure * fourth request: - pass in session - call messages() with classification and compare data structure * fifth request: - pass in session - call messages() with both scope & classification and compare data structure FILES: 04-messages.t, TestAppMessages.pm * clear_messages * first request: - establish session - clear private session var (where messages are stored) - push in a few messages * second request: - pass in session - call clear_messages() - call messages() and compare * recall first request * third request: - pass in session - call clear_messages() with scope - call messages() and compare * recall first request * fourth request: - pass in session - call clear_messages() with classification - call messages() and compare * recall first request * fifth request: - pass in session - call clear_messages() with scope & classification - call messages() and compare FILES: 05-clear_messages.t, TestAppClear.pm * pop_message * first request: - establish session - clear private session var - push in a few messages * second request: - pass in session - call pop_message() and compare * recall first request * third request: - pass in session - call pop_message() with scope and compare * recall first request * fourth request: - pass in session - call pop_message() with classification and compare * recall first request * fifth request: - pass in session - call pop_message() with scope & classification and compare * sixth request: - pass in session - compare the remaining messages() FILES: 06-pop_message.t, TestAppPop.pm * Template Toolkit Test (same as 02-check_output.t, but using CAP-TT) * cgiapp w/ CAP-TT * check for CAP-TT. If ! installed, skip * first request: - establish/check for session - check output for ! message * second request: - pass in session - push an info message * third request: - pass in session - check output for message - check message for proper classification FILES: 07-template_toolkit.t, TestAppTT.pm, output.tt * capms_config w/ Automatic Clearing * cgiapp w/ -automatic_clearing config * first request - establish session - call capms_config with -automatic_clearing - push in some messages * second request - pass in session - check output for message * third request - pass in session - call messages() and compare FILES: 08-capms_config_ac.t, TestAppConfigAC.pm, output.TMPL * capms_config w/ parameter name overrides * cgiapp w/ parameter name configs * first request - establish session - call capms_config with parameter name overrides - push in some messages * second request - pass in session - load original template (output.TMPL) and check for no message * third request - pass in session - load in different template (output_params.TMPL) and check for message * fourth request - pass in session - call messages() and compare FILES: 09-capms_config_params.t, TestAppConfigParams.pm, output.TMPL, output_params.TMPL * capms_config w/ dont_use_session * cgiapp w/ dont_use_session config * first request - push in some messages - check for no messages - load_tmpl and check for output * second request - load_tmpl and check for no messages in output FILES: 10-capms_config_no_session.t, TestAppConfigNoSession.pm, output.TMPL * pod tests FILES: pod.t, pod-coverage.t CGI-Application-Plugin-MessageStack-0.34/t/output_params.TMPL0000644000175000001470000000062710504260761024370 0ustar jasonwebdev00000000000000 cgiapp messagestack output template

hello world

">
CGI-Application-Plugin-MessageStack-0.34/t/TestAppNoSession.pm0000644000175000001470000000100610504260761024536 0ustar jasonwebdev00000000000000package TestAppNoSession; use base 'CGI::Application'; use CGI::Application::Plugin::MessageStack; sub setup { my $self = shift; $self->run_modes( [ qw( start ) ] ); $self->tmpl_path( './t' ); } sub start { my $self = shift; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $self->push_message( -scope => 'start', -message => 'this is a test', -classification => 'ERROR', ); $template->output; } 1;CGI-Application-Plugin-MessageStack-0.34/t/03-scope.t0000644000175000001470000000513410504260761022503 0ustar jasonwebdev00000000000000use Test::More; ## TEST PLAN ## #* cgiapp w/ html-template # * same as before, but check scoping: # - in 2nd request, scope info message for non-existent runmode # - in 3rd request, check for ! message # - in 4th request, scope info message for arrayref runmodes # - in 5th request, check for message (1st arrayref value) # - in 6th request, check for message (2nd arrayref value) # - in 7th request, check for ! message #FILES: 03-scope.t, TestAppScope.pm, output.TMPL use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 6; use CGI; use TestAppScope; my $testapp = TestAppScope->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; my $test_name = "got the expected output"; like( $output, qr/scoped message pushed/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; $test_name = "message is not in the output"; unlike( $output, qr/this is a test/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; $test_name = "pushed the arrayref scope"; like( $output, qr/scoped message with arrayref pushed/, $test_name ); $query->param( -name => 'rm', -value => 'fifth' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the message in first arrayref value scope runmode"; like( $output, qr/arrayref test/, $test_name ); $query->param( -name => 'rm', -value => 'sixth' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the message in second arrayref value scope runmode"; like( $output, qr/arrayref test/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; $test_name = "scoped arrayref message isn't in other runmode"; unlike( $output, qr/arrayref test/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppScope->new( QUERY => $query ); $output = $testapp->run; undef $testapp; CGI-Application-Plugin-MessageStack-0.34/t/09-capms_config_params.t0000644000175000001470000000510510504260761025371 0ustar jasonwebdev00000000000000use Test::More; ## TEST PLAN ## #* capms_config w/ parameter name overrides # * cgiapp w/ parameter name configs # * first request # - establish session # - call capms_config with parameter name overrides # - push in some messages # * second request # - pass in session # - load original template (output.TMPL) and check for no message # * third request # - pass in session # - load in different template (output_params.TMPL) and check for message # * fourth request # - pass in session # - call messages() and compare #FILES: 09-capms_config_params.t, TestAppConfigParams.pm, output.TMPL, output_params.TMPL use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } # The cgiapp adds 1 more test to the mix... plan tests => 9; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppConfigParams; my $testapp = TestAppConfigParams->new(QUERY=>CGI->new()); my $output = $testapp->run(); my $test_name; # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppConfigParams->new( QUERY => $query ); $output = $testapp->run; $test_name = "making sure bad template params aren't being filled"; # testing for an array of data here... unlike( $output, qr/this is a test/, $test_name ); unlike( $output, qr/this is another test/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppConfigParams->new( QUERY => $query ); $output = $testapp->run; $test_name = "making sure good template params are being filled"; like( $output, qr/this is a test/, $test_name ); like( $output, qr/this is another test/, $test_name ); like( $output, qr/got your stuff updated/, $test_name ); like( $output, qr/another info/, $test_name ); like( $output, qr/some bad stuff/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppConfigParams->new( QUERY => $query ); $output = $testapp->run; $test_name = "the message stack compared ok"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppConfigParams->new( QUERY => $query ); $output = $testapp->run; undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; CGI-Application-Plugin-MessageStack-0.34/t/TestAppConfigParams.pm0000644000175000001470000001021110504260761025165 0ustar jasonwebdev00000000000000package TestAppConfigParams; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* capms_config w/ parameter name overrides # * cgiapp w/ parameter name configs # * first request # - establish session # - call capms_config with parameter name overrides # - push in some messages # * second request # - pass in session # - load original template (output.TMPL) and check for no message # * third request # - pass in session # - load in different template (output_params.TMPL) and check for message #FILES: 09-capms_config_params.t, TestAppConfigParams.pm, output.TMPL, output_params.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'third', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'third', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'third', -message => 'some bad stuff', -classification => 'ERROR', ); $self->capms_config( -loop_param_name => 'MyOwnLoopName', -message_param_name => 'MyOwnMessageName', -classification_param_name => 'MyOwnClassificationName', ); return "all set"; } sub second { my $self = shift; my $session = $self->session(); my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub third { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output_params.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub fourth { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { 'MyOwnMessageName' => 'this is a test' }, { 'MyOwnMessageName' => 'this is another test', 'MyOwnClassificationName' => 'INFO' }, { -scope => 'invalid', 'MyOwnMessageName' => 'bad password!', 'MyOwnClassificationName' => 'ERROR' }, { -scope => 'start', 'MyOwnMessageName' => 'there was a problem', 'MyOwnClassificationName' => 'ERROR' }, { -scope => 'third', 'MyOwnMessageName' => 'got your stuff updated', 'MyOwnClassificationName' => 'INFO' }, { -scope => 'third', 'MyOwnMessageName' => 'another info', 'MyOwnClassificationName' => 'INFO' }, { -scope => 'third', 'MyOwnMessageName' => 'some bad stuff', 'MyOwnClassificationName' => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/t/TestAppScope.pm0000644000175000001470000000500310504260761023670 0ustar jasonwebdev00000000000000package TestAppScope; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; ## TEST PLAN ## # * cgiapp w/ html-template # * same as before, but check scoping: # - in 2nd request, scope info message for non-existent runmode # - in 3rd request, check for ! message # - in 4th request, scope info message for arrayref runmodes # - in 5th request, check for message (1st arrayref value) # - in 6th request, check for message (2nd arrayref value) # - in 7th request, check for ! message # FILES: 03-scope.t, TestAppScope.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth fifth sixth cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub second { my $self = shift; my $session = $self->session; $self->push_message( -scope => 'invalid', -message => 'this is a test', -classification => 'ERROR', ); return "scoped message pushed"; } sub third { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub fourth { my $self = shift; my $session = $self->session; $self->push_message( -scope => [ qw( fifth sixth ) ], -message => 'arrayref test', ); return "scoped message with arrayref pushed"; } sub fifth { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub sixth { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/TestAppPop.pm0000644000175000001470000000777010504260761023372 0ustar jasonwebdev00000000000000package TestAppPop; use Test::More; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; ## TEST PLAN ## #* pop_message # * first request: # - establish session # - clear private session var # - push in a few messages # * second request: # - pass in session # - call pop_message() and compare # * recall first request # * third request: # - pass in session # - call pop_message() with scope and compare # * recall first request # * fourth request: # - pass in session # - call pop_message() with classification and compare # * recall first request # * fifth request: # - pass in session # - call pop_message() with scope & classification and compare # * sixth request: # - pass in session # - compare the remaining messages() #FILES: 06-pop_message.t, TestAppPop.pm sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth fifth sixth cleanup ) ] ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR', ); return "all set"; } sub second { my $self = shift; my $session = $self->session; my $message = $self->pop_message(); return ( $message eq 'some bad stuff' ) ? 'succeeded' : 'failed'; } sub third { my $self = shift; my $session = $self->session; my $message = $self->pop_message( -scope => 'start' ); return ( $message eq 'there was a problem' ) ? 'succeeded' : 'failed'; } sub fourth { my $self = shift; my $session = $self->session; my $message = $self->pop_message( -classification => 'INFO' ); return ( $message eq 'another info' ) ? 'succeeded' : 'failed'; } sub fifth { my $self = shift; my $session = $self->session; my $message = $self->pop_message( -scope => 'fourth', -classification => 'INFO' ); return ( $message eq 'got your stuff updated' ) ? 'succeeded' : 'failed'; } sub sixth { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/t/TestAppMessages.pm0000644000175000001470000001263510504260761024377 0ustar jasonwebdev00000000000000package TestAppMessages; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* messages # * first request: # - establish session # - push in a few messages # * second request: # - pass in session # - call messages() and compare data structure # * third request: # - pass in session # - call messages() with scope and compare data structure # * fourth request: # - pass in session # - call messages() with classification and compare data structure # * fifth request: # - pass in session # - call messages() with both scope & classification and compare data structure #FILES: 04-messages.t, TestMessages.pm sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth fifth cleanup ) ] ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR', ); return "all set"; } sub second { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, { -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub third { my $self = shift; my $session = $self->session; my $messages = $self->messages( -scope => 'fourth' ); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, { -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fourth { my $self = shift; my $session = $self->session; my $messages = $self->messages( -classification => 'ERROR' ); my $expectation = [ { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, { -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fifth { my $self = shift; my $session = $self->session; my $messages = $self->messages( -scope => 'fourth', -classification => 'INFO' ); my $expectation = [ { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1;CGI-Application-Plugin-MessageStack-0.34/lib/0000755000175000001470000000000010504260761021265 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/lib/CGI/0000755000175000001470000000000010504260761021667 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/lib/CGI/Application/0000755000175000001470000000000010504260761024132 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/lib/CGI/Application/Plugin/0000755000175000001470000000000010504260761025370 5ustar jasonwebdev00000000000000CGI-Application-Plugin-MessageStack-0.34/lib/CGI/Application/Plugin/MessageStack.pm0000644000175000001470000005276210504260761030314 0ustar jasonwebdev00000000000000package CGI::Application::Plugin::MessageStack; use CGI::Application 4.01; use 5.006; use warnings; use strict; =head1 NAME CGI::Application::Plugin::MessageStack - A message stack for your CGI::Application =head1 VERSION Version 0.34 =cut use vars qw( @ISA $VERSION @EXPORT %config ); @ISA = qw( Exporter AutoLoader ); @EXPORT = qw( push_message pop_message clear_messages messages capms_config ); sub import { my $caller = scalar( caller ); $caller->add_callback( 'load_tmpl' => \&_pass_in_messages ); goto &Exporter::import; } $VERSION = '0.34'; =head1 SYNOPSIS This plugin gives you a few support methods that you can call within your cgiapp to pass along messages between requests for a given user. use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; sub mainpage { my $self = shift; my $template = $self->load_tmpl( 'mainpage.TMPL', 'die_on_bad_params' => 0 ); # ... $template->output; } sub process { my $self = shift; $self->push_message( -scope => 'mainpage', -message => 'Your listing has been updated', -classification => 'INFO', ); $self->forward( 'mainpage' ); } sub cgiapp_init { # setup your session object as usual... } Meanwhile, in your (HTML::Template) template code: ... ...

Howdy!

">
... It's a good idea to turn off 'die_on_bad_params' in HTML::Template - in case this plugin tries to put in the parameters and they're not available in your template. Here's a quick TT example: ...

Howdy!

[% FOREACH CAP_Messages %]
[% message %]
[% END %] ... If you use TT, I recommend using CAP-TT and a more recent version (0.09), which supports cgiapp's load_tmpl hook and then this plugin will automatically supply TT with the relevant messages. Your runmode could be this simple: sub start { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } I don't have the experience to weigh in on how you'd do this with other templates (HTDot, Petal), but basically, this plugin will put in a loop parameter called 'CAP_Messages'. Within each element of that loop, you'll have two tags, 'classification' and 'message'. NOTE: I have broken backwards compatibility with this release (0.30) and the loop parameter's default name is now 'CAP_Messages'. If you used the old __CAP_Messages or want to use another name, feel free to use the capms_config to override the C<-loop_param_name>. =head1 DESCRIPTION This plugin by default needs a session object to tuck away the message(s). It's recommended that you use this in conjunction with CGI::Application::Plugin::Session. You can opt to not have the messages persist and thereby, not use CAP-Session by using the C<-dont_use_session> option in the C method. This plugin hooks into cgiapp's load_tmpl method and if you've pushed any messages in the stack, will automatically add the message parameters. In the functions, there are scope & classification keys and when they're used for either display or your API purposes (clearing, pop'ing, etc), the classification is an exclusive specification. Meaning, if you ask for messages with the 'ERROR' classification, it will only deal with messages that you've pushed in with the 'ERROR' classification. Any messages that have no classification aren't included. The scope key is not exclusive, meaning that if you ask for messages with a 'mainpage' scope, it will deal with messages that you've pushed with that scope B any messages that you've pushed in without a scope. If you use both scope & classification, it blends both of those rules, first getting all matching messages with the same classification and then filtering out messages that are scoped and don't match the scope you're looking for. This logic may change as I get feedback from more saavy developers. What we may end up doing is have a plugin configuration where you can dictate the logic that's used. =head1 FUNCTIONS =head2 push_message $self->push_message( -scope => 'mainpage', -message => 'Your listing has been updated', -classification => 'INFO', ); You provide a hash to the push_message() method with three possible keys: =over =item * message - a text message. You can put HTML in there - just make sure you don't use the ESCAPE=HTML in your HTML::Template code =item * scope - which runmode(s) can this message appear? If you want to specify just one, use a scalar assignment. Otherwise, use an array reference with the list of runmodes. =item * classification - a simple scalar name representing the classification of your message (i.e. 'ERROR', 'WARNING' ... ). This is very useful for CSS styles (see template example above). =back The scope & classification keys are optional. If you don't provide a scope, it will assume a global presence. =cut sub push_message { my $self = shift; my $session = _check_for_session( $self ); my %message_hash = @_; if ( my $message_array = $session->param( '__CAP_MessageStack_Stack' ) ) { push @$message_array, \%message_hash; $session->param( '__CAP_MessageStack_Stack' => $message_array ); } else { $session->param( '__CAP_MessageStack_Stack' => [ \%message_hash ] ); } } =head2 messages my @messages = $self->messages(); my @messages = $self->messages( -scope => 'mainpage' ); my @messages = $self->messages( -scope => 'mainpage', -classification => 'ERROR' ); my @messages = $self->messages( -classification => 'ERROR' ); If you want to take a gander at the message stack data structure, you can use this method. Optionally, you can use a hash parameters to get a slice of the messages, using the same keys as specified in the push_message() method. It will return an array reference of the matching messages or 'undef', if there's either no messages in the stack or no messages that match your specification(s). =cut sub messages { my $self = shift; my $session = _check_for_session( $self ); my %limiting_params = @_; my $message_array = $session->param( '__CAP_MessageStack_Stack' ) || []; if ( $limiting_params{'-scope'} || $limiting_params{'-classification'} ) { $message_array = _filter_messages( $message_array, \%limiting_params ) } else { # if the dev config'd different message or classification names, i need to do # 'em by hand here ... _filter_messages() would do that, but only if they # wanted a slice. This is if they want everything. if ( my $class_key = $config{'-classification_param_name'} ) { map { if ( $_->{'-classification'} ) { $_->{$class_key} = $_->{'-classification'}; delete $_->{'-classification'}; } } @$message_array; } if ( my $message_key = $config{'-message_param_name'} ) { map { if ( $_->{'-message'} ) { $_->{$message_key} = $_->{'-message'}; delete $_->{'-message'}; } } @$message_array; } } return $message_array; } =head2 pop_message my $message = $self->pop_message(); my $message = $self->pop_message( -scope => 'mainpage' ); my $message = $self->pop_message( -scope => 'mainpage', -classification => 'WARNING' ); my $message = $self->pop_message( -classification => 'ERROR' ); Pops off the last message from the stack and returns it. Note that this just returns the -message part. You can pop off an exact message, given a hash parameters, using the same keys as specified in the push_message() method. Otherwise, it will pop off the message, given the current runmode and the last message added. =cut sub pop_message { my $self = shift; my $session = _check_for_session( $self ); my %limiting_params = @_; my $message; my $message_array = $session->param( '__CAP_MessageStack_Stack' ); if ( $config{'-dont_use_session'} ) { $session->param( '__CAP_MessageStack_Stack' => undef ); } else { $session->clear( [ '__CAP_MessageStack_Stack' ] ); } if ( $limiting_params{'-scope'} || $limiting_params{'-classification'} ) { my $index = scalar( @$message_array ) - 1; foreach my $message_hashref ( reverse @$message_array ) { # now we're looking for the first matching element ... if/when we find it, # set the $message and splice out the element from the $message_array my $match_found = 0; if ( $limiting_params{'-scope'} && $limiting_params{'-classification'} ) { if ( ( ! $message_hashref->{'-scope'} || ( ( ref( $message_hashref->{'-scope'} ) && grep { $_ eq $limiting_params{'-scope'} } @{$message_hashref->{'-scope'}} ) || ( ! ref ( $message_hashref->{'-scope'} ) && $message_hashref->{'-scope'} eq $limiting_params{'-scope'} ) ) ) && ( $message_hashref->{'-classification'} && $message_hashref->{'-classification'} eq $limiting_params{'-classification'} ) ) { $match_found = 1; $message = $message_hashref->{'-message'}; } } elsif ( $limiting_params{'-scope'} ) { if ( ! $message_hashref->{'-scope'} ) { $match_found = 1; $message = $message_hashref->{'-message'}; } else { if ( ref( $message_hashref->{'-scope'} ) ) { if ( grep { $_ eq $limiting_params{'-scope'} } @{$message_hashref->{'-scope'}} ) { $match_found = 1; $message = $message_hashref->{'-message'}; } } else { if ( $message_hashref->{'-scope'} eq $limiting_params{'-scope'} ) { $match_found = 1; $message = $message_hashref->{'-message'}; } } } } elsif ( $limiting_params{'-classification'} ) { if ( $message_hashref->{'-classification'} && $message_hashref->{'-classification'} eq $limiting_params{'-classification'} ) { $match_found = 1; $message = $message_hashref->{'-message'}; } } if ( $match_found ) { splice( @$message_array, $index, 1 ); last; } $index--; } } else { my $message_hashref = pop @$message_array; $message = $message_hashref->{'-message'}; } $session->param( '__CAP_MessageStack_Stack' => $message_array ); $message; } =head2 clear_messages $self->clear_messages(); $self->clear_messages( -scope => 'mainpage' ); $self->clear_messages( -scope => 'mainpage', -classification => 'ERROR' ); $self->clear_messages( -classification => 'ERROR' ); Clears the message stack. Optionally, you can clear particular slices of the message stack, given a hash parameters, using the same keys as specified in the push_message() method. If you specify a scope, it will clear any messages that are either global or match that scope If you specify a classification, it will clear any messages that have that classification (but not any messages that don't have any classification). If you specify both, it will combine both that logic in an AND fashion. =cut sub clear_messages { my $self = shift; my $session = _check_for_session( $self ); my %limiting_params = @_; if ( $limiting_params{'-scope'} || $limiting_params{'-classification'} ) { my $message_array = $session->param( '__CAP_MessageStack_Stack' ); # can't use filter, b/c we need to invert that result... my $nonmatching_messages = []; if ( $limiting_params{'-classification'} && $limiting_params{'-scope'} ) { foreach my $message_hashref ( @$message_array ) { next if ( $message_hashref->{'-classification'} && $message_hashref->{'-classification'} eq $limiting_params{'-classification'} ) && ( !$message_hashref->{'-scope'} || ( ( ref( $message_hashref->{'-scope'} ) && grep { $_ eq $limiting_params{'-scope'} } @{$message_hashref->{'-scope'}} ) || ( ! ref( $message_hashref->{'-scope'} ) && $message_hashref->{'-scope'} eq $limiting_params{'-scope'} ) ) ); push @$nonmatching_messages, $message_hashref; } } elsif ( $limiting_params{'-classification'} ) { foreach my $message_hashref ( @$message_array ) { next if $message_hashref->{'-classification'} && $message_hashref->{'-classification'} eq $limiting_params{'-classification'}; push @$nonmatching_messages, $message_hashref; } } elsif ( $limiting_params{'-scope'} ) { foreach my $message_hashref ( @$message_array ) { next if ! $message_hashref->{'-scope'}; # taking out global scopes if ( ref( $message_hashref->{'-scope'} ) ) { next if grep { $_ eq $limiting_params{'-scope'} } @{$message_hashref->{'-scope'}}; } else { next if $message_hashref->{'-scope'} eq $limiting_params{'-scope'}; # taking out matching scopes } push @$nonmatching_messages, $message_hashref; } } $session->param( '__CAP_MessageStack_Stack' => $nonmatching_messages ); } else { if ( $config{'-dont_use_session'} ) { $session->param( '__CAP_MessageStack_Stack' => undef ); } else { $session->clear( [ '__CAP_MessageStack_Stack' ] ); } } } =head2 capms_config $self->capms_config( -automatic_clearing => 1, -dont_use_session => 1, -loop_param_name => 'MyOwnLoopName', -message_param_name => 'MyOwnMessageName', -classification_param_name => 'MyOwnClassificationName', ); There is a configuration option that you, as the developer can specify: =over =item * -automatic_clearing: By default, this is turned off. If you override it with a true value, it will call clear_messages() automatically after the messages are automatically put into template. =item * -dont_use_session: This will override this Plugin's dependence on CGI::Application::Plugin::Session and instead, temporarily store the message data such that it will be available to templates within the same web request, but no further. If you're running your cgiapp under a persistent state (mod_perl), we'll also make sure your messages are gone by the end of the request. =item * -loop_param_name: This will override the default __CAP_Messages (or CAP_Messages for TT users) name for the loop of messages, which is only used for the C callback. Meaning, this configuration will only impact your template code. So if you use the 'MyOwnLoopName' above, then your template code (for HTML::Template users) should look like: ... =item * -message_param_name: This will override the default '-message' in both the template code B the keys in each hashref of the arrayref that's returned by the messages() function. So a call to messages() may return: [ { 'MyOwnMessageName' => 'this is just a test' }, ... ] instead of: [ { '-message' => 'this is just a test' }, ... ] Likewise, your templates will need to use your parameter name: Here's the message: =item * -classification_param_name: Just like the C<-message_param_name> parameter - this will override the default '-classification' key in both the template code B the keys in each hashref of the arrayref that's returned by the messages() function. So a call to messages() may return: [ { 'MyOwnClassificationName' => 'ERROR', 'MyOwnMessageName' => 'this is just a test' }, ... ] instead of: [ { '-classification' => 'ERROR', '-message' => 'this is just a test' }, ... ] Likewise, your templates will need to use your parameter name:
"> Here's the message:
=back =cut sub capms_config { my $self = shift; %config = @_; } sub _filter_messages { my ( $messages, $limiting_params, $for_template ) = @_; my $matching_messages = []; my $class_key = $config{'-classification_param_name'} || 'classification'; my $message_key = $config{'-message_param_name'} || 'message'; if ( $limiting_params->{'-classification'} && $limiting_params->{'-scope'} ) { foreach my $message_hashref ( @$messages ) { next if !$message_hashref->{'-classification'} || $message_hashref->{'-classification'} ne $limiting_params->{'-classification'}; if ( ref( $message_hashref->{'-scope'} ) ) { next if ! grep { $_ eq $limiting_params->{'-scope'} } @{$message_hashref->{'-scope'}}; } else { next if $message_hashref->{'-scope'} && $message_hashref->{'-scope'} ne $limiting_params->{'-scope'}; } # i'm beginning to hate the dash now ... now i have to take 'em out # so the template code doesn't need/use 'em... if ( $for_template ) { push @$matching_messages, { $class_key => $message_hashref->{'-classification'}, $message_key => $message_hashref->{'-message'}, }; } else { push @$matching_messages, $message_hashref; } } } elsif ( $limiting_params->{'-classification'} ) { foreach my $message_hashref ( @$messages ) { next if !$message_hashref->{'-classification'} || $message_hashref->{'-classification'} ne $limiting_params->{'-classification'}; if ( $for_template ) { push @$matching_messages, { $class_key => $message_hashref->{'-classification'}, $message_key => $message_hashref->{'-message'}, }; } else { push @$matching_messages, $message_hashref; } } } elsif ( $limiting_params->{'-scope'} ) { foreach my $message_hashref ( @$messages ) { if ( ref( $message_hashref->{'-scope'} ) ) { next if ! grep { $_ eq $limiting_params->{'-scope'} } @{$message_hashref->{'-scope'}}; } else { next if $message_hashref->{'-scope'} && $message_hashref->{'-scope'} ne $limiting_params->{'-scope'}; } if ( $for_template ) { push @$matching_messages, { $class_key => $message_hashref->{'-classification'}, $message_key => $message_hashref->{'-message'}, }; } else { push @$matching_messages, $message_hashref; } } } return $matching_messages; } sub _pass_in_messages { my ( $self, undef, $tmpl_params, undef ) = @_; # get the proper messages and update $tmpl_params my $session = _check_for_session( $self ); my $current_runmode = $self->get_current_runmode(); my $message_stack = $session->param( '__CAP_MessageStack_Stack' ); my $messages = _filter_messages( $message_stack, { -scope => $current_runmode }, 1 ); my $loop_name = $config{'-loop_param_name'} || 'CAP_Messages'; $tmpl_params->{ $loop_name } = $messages if scalar( @$messages ); $self->clear_messages( -scope => $current_runmode ) if ( $config{'-automatic_clearing'} ); } # This method will return an object, depending on if the developer wants to # use a session (the default behavior) or just the cgiapp itself. sub _check_for_session { my $self = shift; my $session_object = undef; if ( $config{'-dont_use_session'} ) { $session_object = $self; } else { # dynamic importing of CAP-Session eval { require CGI::Application::Plugin::Session; CGI::Application::Plugin::Session->import(); $session_object = $self->session; }; if ( $@ || ! $session_object ) { die "No session object! This module depends on CGI::Application::Plugin::Session! (or you need to use the -dont_use_session config parameter)" } } return $session_object; } =head1 AUTHOR Jason Purdy, C<< >> =head1 SEE ALSO L and L =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. I suspect that this code could use some expert guidance. I hacked it together and I'd hate to think that it would be responsible for slowing templates down. Please feel free to submit patches, guiding comments, etc. =head1 ACKNOWLEDGEMENTS Thanks to the guys on the #cgiapp channel =head1 COPYRIGHT & LICENSE Copyright 2005 Jason Purdy, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of CGI::Application::Plugin::MessageStack __END__ CGI-Application-Plugin-MessageStack-0.34/Changes0000644000175000001470000000540410504260761022015 0ustar jasonwebdev00000000000000Revision history for CGI-Application-Plugin-MessageStack Wed Sep 20 11:41:20 EDT 2006 Jason@Purdy.INFO * 0.34 * Updated test suite with CAP::TT change Fri Mar 31 10:15:16 EST 2006 Jason@Purdy.INFO * 0.33 * Added support for arrayrefs for the -scope parameter * Updated scope testing plan & files Wed Oct 5 10:03:50 EDT 2005 Jason@Purdy.INFO * 0.32 * Fixed test file for TT (bad failures for versions < 0.09) * Added CAP-TT 0.09 to Build.PL (recommends) - Thanks, Shawn! * Fixed test files in case someone doesn't have CAP-Session installed Thu Sep 29 09:32:52 EDT 2005 Jason@Purdy.INFO * 0.31 * Added Makefile.PL to MANIFEST so CPAN.pm & cpanplus will pick it up & tests will pass * Moved CAP-Session from required to recommends since developer can opt to not use it. * Updated docs Fri Sep 23 22:36:56 EDT 2005 Jason@Purdy.INFO * 0.30 * Added param name overrides in capms_config * Added optional session in capms_config * Added test scripts * Changed default loop param name to CAP_Messages (no preceding underscores) * Updated docs Fri Sep 23 15:55:02 EDT 2005 Jason@Purdy.INFO * 0.21 * Added __END__ to module * Added create_makefile_pl to Build.PL * Updated docs Fri Sep 23 14:30:59 EDT 2005 Jason@Purdy.INFO * 0.20 * Added capms_config w/ support for automatic_clearing * Added test script for automatic_clearing * Added test case for non-automatic_clearing (02-check_output.t) * Updated cgiapp requirement to 4 in Build.PL * Added any orphan cgisess files in the test dir to cleanup Fri Sep 23 12:36:28 EDT 2005 Jason@Purdy.INFO * 0.12 * Added a TODO section * Fixed a minor doc bug Fri Sep 23 10:35:50 EDT 2005 Jason@Purdy.INFO * 0.11_rc1 * added template toolkit test * added branch in callback code to support different var. name for TT * updated docs Thu Sep 22 14:18:23 EDT 2005 Jason@Purdy.INFO * 0.10_rc3 * minor changes to the docs - ready to roll now! Thu Sep 22 13:58:48 EDT 2005 Jason@Purdy.INFO * 0.10_rc2 * added README creation to Build.PL * removed static README * changed version number in module Thu Sep 22 13:54:41 EDT 2005 Jason@Purdy.INFO * 0.10_rc1 * first release-worthy version of the plugin * fully functional * test cases for all public API's Thu Sep 15 18:45:11 EDT 2005 Jason@Purdy.INFO * first_test * Got the first test case in place and working Tue Sep 13 21:18:28 EDT 2005 Jason@Purdy.INFO * testplan * added testplan doc Tue Sep 13 21:17:44 EDT 2005 Jason@Purdy.INFO * docs * Added proper documentation Tue Sep 13 15:56:59 EDT 2005 Jason@Purdy.INFO * initial_2 Tue Sep 13 15:55:45 EDT 2005 Jason@Purdy.INFO * skeleton * This is just the basic skeleton that Module::Starter gave me CGI-Application-Plugin-MessageStack-0.34/MANIFEST0000644000175000001470000000124510504260761021652 0ustar jasonwebdev00000000000000Build.PL Changes MANIFEST META.yml # Will be created by "make dist" README Makefile.PL # Will be created by 'make dist' lib/CGI/Application/Plugin/MessageStack.pm t/00-load.t t/01-nosession.t t/02-check_output.t t/03-scope.t t/04-messages.t t/05-clear_messages.t t/06-pop_message.t t/07-template_toolkit.t t/08-capms_config_ac.t t/09-capms_config_params.t t/10-capms_config_no_session.t t/pod-coverage.t t/pod.t t/TestAppClear.pm t/TestAppMessages.pm t/TestAppNoSession.pm t/TestAppOutput.pm t/TestAppPop.pm t/TestAppScope.pm t/TestAppTT.pm t/TestAppConfigAC.pm t/TestAppConfigParams.pm t/TestAppConfigNoSession.pm t/output.TMPL t/output_params.TMPL t/output.tt t/testplan.txt CGI-Application-Plugin-MessageStack-0.34/META.yml0000644000175000001470000000073010504260761021770 0ustar jasonwebdev00000000000000--- name: CGI-Application-Plugin-MessageStack version: 0.34 author: - Jason Purdy abstract: A message stack for your CGI::Application license: perl requires: CGI::Application: 4.01 Test::More: 0 recommends: CGI::Application::Plugin::Session: 0 CGI::Application::Plugin::TT: 0.09 provides: CGI::Application::Plugin::MessageStack: file: lib/CGI/Application/Plugin/MessageStack.pm version: 0.34 generated_by: Module::Build version 0.26 CGI-Application-Plugin-MessageStack-0.34/Build.PL0000644000175000001470000000140410504260761022012 0ustar jasonwebdev00000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'CGI::Application::Plugin::MessageStack', license => 'perl', dist_author => 'Jason Purdy ', dist_version_from => 'lib/CGI/Application/Plugin/MessageStack.pm', requires => { 'Test::More' => 0, 'CGI::Application' => 4.01, }, recommends => { 'CGI::Application::Plugin::Session' => 0, 'CGI::Application::Plugin::TT' => 0.09, }, create_readme => 1, create_makefile_pl => 'traditional', add_to_cleanup => [ 'CGI-Application-Plugin-MessageStack-*', 't/cgisess_*' ], ); $builder->create_build_script(); CGI-Application-Plugin-MessageStack-0.34/README0000644000175000001470000002603310504260761021403 0ustar jasonwebdev00000000000000NAME CGI::Application::Plugin::MessageStack - A message stack for your CGI::Application VERSION Version 0.34 SYNOPSIS This plugin gives you a few support methods that you can call within your cgiapp to pass along messages between requests for a given user. use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; sub mainpage { my $self = shift; my $template = $self->load_tmpl( 'mainpage.TMPL', 'die_on_bad_params' => 0 ); # ... $template->output; } sub process { my $self = shift; $self->push_message( -scope => 'mainpage', -message => 'Your listing has been updated', -classification => 'INFO', ); $self->forward( 'mainpage' ); } sub cgiapp_init { # setup your session object as usual... } Meanwhile, in your (HTML::Template) template code: ... ...

Howdy!

">
... It's a good idea to turn off 'die_on_bad_params' in HTML::Template - in case this plugin tries to put in the parameters and they're not available in your template. Here's a quick TT example: ...

Howdy!

[% FOREACH CAP_Messages %]
[% message %]
[% END %] ... If you use TT, I recommend using CAP-TT and a more recent version (0.09), which supports cgiapp's load_tmpl hook and then this plugin will automatically supply TT with the relevant messages. Your runmode could be this simple: sub start { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } I don't have the experience to weigh in on how you'd do this with other templates (HTDot, Petal), but basically, this plugin will put in a loop parameter called 'CAP_Messages'. Within each element of that loop, you'll have two tags, 'classification' and 'message'. NOTE: I have broken backwards compatibility with this release (0.30) and the loop parameter's default name is now 'CAP_Messages'. If you used the old __CAP_Messages or want to use another name, feel free to use the capms_config to override the "-loop_param_name". DESCRIPTION This plugin by default needs a session object to tuck away the message(s). It's recommended that you use this in conjunction with CGI::Application::Plugin::Session. You can opt to not have the messages persist and thereby, not use CAP-Session by using the "-dont_use_session" option in the "capms_config" method. This plugin hooks into cgiapp's load_tmpl method and if you've pushed any messages in the stack, will automatically add the message parameters. In the functions, there are scope & classification keys and when they're used for either display or your API purposes (clearing, pop'ing, etc), the classification is an exclusive specification. Meaning, if you ask for messages with the 'ERROR' classification, it will only deal with messages that you've pushed in with the 'ERROR' classification. Any messages that have no classification aren't included. The scope key is not exclusive, meaning that if you ask for messages with a 'mainpage' scope, it will deal with messages that you've pushed with that scope as well as any messages that you've pushed in without a scope. If you use both scope & classification, it blends both of those rules, first getting all matching messages with the same classification and then filtering out messages that are scoped and don't match the scope you're looking for. This logic may change as I get feedback from more saavy developers. What we may end up doing is have a plugin configuration where you can dictate the logic that's used. FUNCTIONS push_message $self->push_message( -scope => 'mainpage', -message => 'Your listing has been updated', -classification => 'INFO', ); You provide a hash to the push_message() method with three possible keys: * message - a text message. You can put HTML in there - just make sure you don't use the ESCAPE=HTML in your HTML::Template code * scope - which runmode(s) can this message appear? If you want to specify just one, use a scalar assignment. Otherwise, use an array reference with the list of runmodes. * classification - a simple scalar name representing the classification of your message (i.e. 'ERROR', 'WARNING' ... ). This is very useful for CSS styles (see template example above). The scope & classification keys are optional. If you don't provide a scope, it will assume a global presence. messages my @messages = $self->messages(); my @messages = $self->messages( -scope => 'mainpage' ); my @messages = $self->messages( -scope => 'mainpage', -classification => 'ERROR' ); my @messages = $self->messages( -classification => 'ERROR' ); If you want to take a gander at the message stack data structure, you can use this method. Optionally, you can use a hash parameters to get a slice of the messages, using the same keys as specified in the push_message() method. It will return an array reference of the matching messages or 'undef', if there's either no messages in the stack or no messages that match your specification(s). pop_message my $message = $self->pop_message(); my $message = $self->pop_message( -scope => 'mainpage' ); my $message = $self->pop_message( -scope => 'mainpage', -classification => 'WARNING' ); my $message = $self->pop_message( -classification => 'ERROR' ); Pops off the last message from the stack and returns it. Note that this just returns the -message part. You can pop off an exact message, given a hash parameters, using the same keys as specified in the push_message() method. Otherwise, it will pop off the message, given the current runmode and the last message added. clear_messages $self->clear_messages(); $self->clear_messages( -scope => 'mainpage' ); $self->clear_messages( -scope => 'mainpage', -classification => 'ERROR' ); $self->clear_messages( -classification => 'ERROR' ); Clears the message stack. Optionally, you can clear particular slices of the message stack, given a hash parameters, using the same keys as specified in the push_message() method. If you specify a scope, it will clear any messages that are either global or match that scope If you specify a classification, it will clear any messages that have that classification (but not any messages that don't have any classification). If you specify both, it will combine both that logic in an AND fashion. capms_config $self->capms_config( -automatic_clearing => 1, -dont_use_session => 1, -loop_param_name => 'MyOwnLoopName', -message_param_name => 'MyOwnMessageName', -classification_param_name => 'MyOwnClassificationName', ); There is a configuration option that you, as the developer can specify: * -automatic_clearing: By default, this is turned off. If you override it with a true value, it will call clear_messages() automatically after the messages are automatically put into template. * -dont_use_session: This will override this Plugin's dependence on CGI::Application::Plugin::Session and instead, temporarily store the message data such that it will be available to templates within the same web request, but no further. If you're running your cgiapp under a persistent state (mod_perl), we'll also make sure your messages are gone by the end of the request. * -loop_param_name: This will override the default __CAP_Messages (or CAP_Messages for TT users) name for the loop of messages, which is only used for the "load_tmpl" callback. Meaning, this configuration will only impact your template code. So if you use the 'MyOwnLoopName' above, then your template code (for HTML::Template users) should look like: ... * -message_param_name: This will override the default '-message' in both the template code as well as the keys in each hashref of the arrayref that's returned by the messages() function. So a call to messages() may return: [ { 'MyOwnMessageName' => 'this is just a test' }, ... ] instead of: [ { '-message' => 'this is just a test' }, ... ] Likewise, your templates will need to use your parameter name: Here's the message: * -classification_param_name: Just like the "-message_param_name" parameter - this will override the default '-classification' key in both the template code as well as the keys in each hashref of the arrayref that's returned by the messages() function. So a call to messages() may return: [ { 'MyOwnClassificationName' => 'ERROR', 'MyOwnMessageName' => 'this is just a test' }, ... ] instead of: [ { '-classification' => 'ERROR', '-message' => 'this is just a test' }, ... ] Likewise, your templates will need to use your parameter name:
"> Here's the message:
AUTHOR Jason Purdy, "" SEE ALSO CGI::Application and CGI::Application::Plugin::Session BUGS Please report any bugs or feature requests to "bug-cgi-application-plugin-messagestack@rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. I suspect that this code could use some expert guidance. I hacked it together and I'd hate to think that it would be responsible for slowing templates down. Please feel free to submit patches, guiding comments, etc. ACKNOWLEDGEMENTS Thanks to the guys on the #cgiapp channel COPYRIGHT & LICENSE Copyright 2005 Jason Purdy, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. CGI-Application-Plugin-MessageStack-0.34/Makefile.PL0000644000175000001470000000074510504260761022477 0ustar jasonwebdev00000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'CGI::Application::Plugin::MessageStack', 'VERSION_FROM' => 'lib/CGI/Application/Plugin/MessageStack.pm', 'PREREQ_PM' => { 'CGI::Application' => '4.01', 'Test::More' => '0' }, 'INSTALLDIRS' => 'site', 'PL_FILES' => {} ) ;