Changeset 24447
- Timestamp:
- 11/20/08 16:19:39 (7 weeks ago)
- Location:
- lang/perl/NanoA/trunk
- Files:
-
- 2 added
- 3 modified
-
app/tinybbs/start.pm (modified) (1 diff)
-
lib/NanoA.pm (modified) (3 diffs)
-
lib/NanoA/Dispatch.pm (modified) (1 diff)
-
plugin (added)
-
plugin/mobile.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/NanoA/trunk/app/tinybbs/start.pm
r23704 r24447 3 3 use strict; 4 4 use warnings; 5 use utf8; 6 7 use plugin::mobile; 5 8 6 9 use base qw(NanoA); -
lang/perl/NanoA/trunk/lib/NanoA.pm
r24441 r24447 9 9 my %REQUIRED; 10 10 my %LOADED; 11 my %HOOKS; 11 12 12 13 BEGIN { 13 14 %REQUIRED = (); 14 15 %LOADED = (); 16 %HOOKS = ( 17 prerun => {}, 18 postrun => {}, 19 ); 15 20 }; 16 21 … … 18 23 my ($klass, $config) = @_; 19 24 my $self = bless { 20 config => $config,21 query => undef,22 headers => {25 config => $config, 26 query => undef, 27 headers => { 23 28 -type => 'text/html', 24 29 -charset => 'utf8', 25 30 }, 26 prerun_hooks => [], 27 postrun_hooks => [], 28 stash => {}, 31 stash => {}, 29 32 }, $klass; 30 33 $self; 31 34 } 32 35 33 sub prerun { 34 my $self = shift; 35 foreach my $h (@{$self->prerun_hooks}) { 36 $h->($self); 37 } 38 } 39 40 sub postrun { 41 my ($self, $bodyref) = @_; 42 foreach my $h (@{$self->postrun_hooks}) { 43 $h->($self, $bodyref); 44 } 36 sub run_hooks { 37 my $self = shift; 38 my $mode = shift; 39 my $hooks = $HOOKS{$mode}->{ref $self} 40 or return; 41 $_->($self, @_) 42 for @$hooks; 43 } 44 45 sub register_hook { 46 my ($klass, $mode, $func) = @_; 47 die "unknown hook: $mode\n" 48 unless $HOOKS{$mode}; 49 my $target = $HOOKS{$mode}->{ref $klass || $klass} ||= []; 50 push @$target, $func; 45 51 } 46 52 … … 65 71 my $self = shift; 66 72 $self->{headers}; 67 }68 69 sub prerun_hooks {70 my $self = shift;71 $self->{prerun_hooks};72 }73 74 sub postrun_hooks {75 my $self = shift;76 $self->{postrun_hooks};77 73 } 78 74 -
lang/perl/NanoA/trunk/lib/NanoA/Dispatch.pm
r24441 r24447 31 31 my $handler = $handler_klass->new($config); 32 32 $config->init_app($handler); 33 $handler->prerun(); 33 34 $handler->run_hooks('prerun'); 34 35 my $body = $handler->run(); 35 $handler-> postrun(\$body);36 $handler->run_hooks('postrun', \$body); 36 37 37 38 $handler->print_header();
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)