import of rt 3.0.9
[freeside.git] / rt / html / Elements / Callback
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <%once>
25 my (%cache, $check);
26 </%once>
27 <%init>
28 # checks for inode change time for each callback directory
29 my $new_check = join(
30     $;, map { $_->[1] => (stat("$_->[1]/Callbacks"))[10] } $m->interp->resolver->comp_root_array
31 ) or return;
32
33 $Page = $m->callers(1)->path unless ($Page);
34
35 my $callbacks;
36 if ($new_check eq $check) {
37     $callbacks = $cache{$Page,$_CallbackName};
38 }
39 else {
40     $check = $new_check;
41 }
42
43 if (!$callbacks) {
44     my $path = "/Callbacks/*$Page/$_CallbackName";
45     $callbacks = [ $m->interp->resolver->glob_path($path) ];
46     @$callbacks = grep !/^\.|~$/, @$callbacks; #skip backup files
47
48     #skip files without a package
49     my $invalid_base = "/Callbacks/$Page/$_CallbackName";
50     @$callbacks = grep !/^$invalid_base$/, @$callbacks;
51
52
53
54     $cache{$Page,$_CallbackName} = $callbacks;
55 }
56
57 my @rv;
58 foreach my $comp (sort @$callbacks) {
59         push @rv, $m->comp($comp, %ARGS) if $m->comp_exists($comp);
60 }
61 return @rv;
62 </%init>
63 <%args>
64 $_CallbackName => 'Default'
65 $Page => undef
66 </%args>