Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r16139: LJSV-908 (on dev servers, reload hooks f...

Committer: ailyin
LJSV-908 (on dev servers, reload hooks from a module when this module is reloaded)

U   trunk/cgi-bin/Apache/LiveJournal.pm
U   trunk/cgi-bin/ljhooks.pl
Modified: trunk/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- trunk/cgi-bin/Apache/LiveJournal.pm	2010-01-26 08:02:50 UTC (rev 16138)
+++ trunk/cgi-bin/Apache/LiveJournal.pm	2010-01-26 11:26:37 UTC (rev 16139)
@@ -155,6 +155,8 @@
 
             foreach my $file (keys %to_reload) {
                 print STDERR "Reloading $file...\n";
+                LJ::clear_hooks($file);
+
                 my %reloaded;
                 local $SIG{__WARN__} = sub {
                     if ($_[0] =~ m/^Subroutine (\S+) redefined at /)

Modified: trunk/cgi-bin/ljhooks.pl
===================================================================
--- trunk/cgi-bin/ljhooks.pl	2010-01-26 08:02:50 UTC (rev 16138)
+++ trunk/cgi-bin/ljhooks.pl	2010-01-26 11:26:37 UTC (rev 16139)
@@ -25,8 +25,17 @@
 # </LJFUNC>
 sub clear_hooks
 {
-    %LJ::HOOKS = ();
-    $hooks_dir_scanned = 0;
+    my ($filename) = @_;
+
+    if (!$filename) {
+        %LJ::HOOKS = ();
+        $hooks_dir_scanned = 0;
+    } else {
+        foreach my $hookname (keys %LJ::HOOKS) {
+            @{$LJ::HOOKS{$hookname}} = grep { $_->[0] ne $filename }
+                @{$LJ::HOOKS{$hookname}};
+        }
+    }
 }
 
 # <LJFUNC>
@@ -44,7 +53,7 @@
 
     my @ret;
     foreach my $hook (@{$LJ::HOOKS{$hookname} || []}) {
-        push @ret, [ $hook->(@args) ];
+        push @ret, [ $hook->[1]->(@args) ];
     }
     return @ret;
 }
@@ -62,7 +71,7 @@
     load_hooks_dir() unless $hooks_dir_scanned;
 
     return undef unless @{$LJ::HOOKS{$hookname} || []};
-    return $LJ::HOOKS{$hookname}->[0]->(@args);
+    return $LJ::HOOKS{$hookname}->[0]->[1]->(@args);
 }
 
 # <LJFUNC>
@@ -77,7 +86,9 @@
 {
     my $hookname = shift;
     my $subref = shift;
-    push @{$LJ::HOOKS{$hookname}}, $subref;
+    my (undef, $filename, undef) = caller;
+
+    push @{$LJ::HOOKS{$hookname}}, [$filename, $subref];
 }
 
 sub load_hooks_dir {

Tags: andy, livejournal, pl, pm
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments