| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              #!/usr/bin/perl  | 
            
            
              | 2 | 
              use Plack::Builder;  | 
            
            
              | 3 | 
              use Plack::App::CGIBin;  | 
            
            
              | 4 | 
              use lib qw( ./lib );  | 
            
            
              | 5 | 
              use Plack::Middleware::Debug;  | 
            
            
              | 6 | 
              use Plack::App::Directory;  | 
            
            
              | 7 | 
               | 
            
            
              | 8 | 
              BEGIN { | 
            
            
              | 9 | 
               | 
            
            
              | 10 | 
              # override configuration from startup script below:  | 
            
            
              | 11 | 
              # (requires --reload option)  | 
            
            
              | 12 | 
               | 
            
            
              | 13 | 
              $ENV{PLACK_DEBUG} = 1; # toggle debugging | 
            
            
              | 14 | 
               | 
            
            
              | 15 | 
              # memcache change requires restart  | 
            
            
              | 16 | 
              $ENV{MEMCACHED_SERVERS} = "localhost:11211"; | 
            
            
              | 17 | 
              #$ENV{MEMCACHED_DEBUG} = 0; | 
            
            
              | 18 | 
               | 
            
            
              | 19 | 
              $ENV{PROFILE_PER_PAGE} = 1; # reset persistant and profile counters after each page, like CGI | 
            
            
              | 20 | 
              #$ENV{INTRANET} = 1; # usually passed from script | 
            
            
              | 21 | 
               | 
            
            
              | 22 | 
              #$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=null;cache=DBI::Util::CacheMemory' | 
            
            
              | 23 | 
               | 
            
            
              | 24 | 
              } # BEGIN  | 
            
            
              | 25 | 
               | 
            
            
              | 26 | 
              use C4::Context;  | 
            
            
              | 27 | 
              use C4::Languages;  | 
            
            
              | 28 | 
              use C4::Members;  | 
            
            
              | 29 | 
              use C4::Dates;  | 
            
            
              | 30 | 
              use C4::Boolean;  | 
            
            
              | 31 | 
              use C4::Letters;  | 
            
            
              | 32 | 
              use C4::Koha;  | 
            
            
              | 33 | 
              use C4::XSLT;  | 
            
            
              | 34 | 
              use C4::Branch;  | 
            
            
              | 35 | 
              use C4::Category;  | 
            
            
              | 36 | 
              =for preload  | 
            
            
              | 37 | 
              use C4::Tags; # FIXME  | 
            
            
              | 38 | 
              =cut  | 
            
            
              | 39 | 
               | 
            
            
              | 40 | 
              use Devel::Size 0.77; # 0.71 doesn't work for Koha  | 
            
            
              | 41 | 
              my $watch_capture_regex = '(C4|Koha)';  | 
            
            
              | 42 | 
               | 
            
            
              | 43 | 
              sub watch_for_size { | 
            
            
              | 44 | 
              	my @watch =  | 
            
            
              | 45 | 
              	map { s/^.*$watch_capture_regex/$1/; s/\//::/g; s/\.pm$//; $_ } # fix paths | 
            
            
              | 46 | 
              	grep { /$watch_capture_regex/ } | 
            
            
              | 47 | 
              	keys %INC  | 
            
            
              | 48 | 
              	;  | 
            
            
              | 49 | 
              	warn "# watch_for_size ",join(' ',@watch); | 
            
            
              | 50 | 
              	return @watch;  | 
            
            
              | 51 | 
              };  | 
            
            
              | 52 | 
               | 
            
            
              | 53 | 
              my $CGI_ROOT = $ENV{INTRANET} ? $ENV{INTRANETDIR} : $ENV{OPACDIR}; | 
            
            
              | 54 | 
              warn "# using Koha ", $ENV{INTRANET} ? 'intranet' : 'OPAC', " CGI from $CGI_ROOT\n"; | 
            
            
              | 55 | 
              my $app=Plack::App::CGIBin->new(root => $CGI_ROOT);  | 
            
            
              | 56 | 
               | 
            
            
              | 57 | 
              builder { | 
            
            
              | 58 | 
               | 
            
            
              | 59 | 
              	# please don't use plugins which are under enable_if $ENV{PLACK_DEBUG} in production! | 
            
            
              | 60 | 
              	# they are known to leek memory  | 
            
            
              | 61 | 
              	enable_if { $ENV{PLACK_DEBUG} } 'Debug',  panels => [ | 
            
            
              | 62 | 
              		qw(Environment Response Timer Memory),  | 
            
            
              | 63 | 
              		# optional plugins (uncomment to enable) are sorted according to performance implact  | 
            
            
              | 64 | 
              #		[ 'Devel::Size', for => \&watch_for_size ], # https://github.com/dpavlin/p5-plack-devel-debug-devel-size  | 
            
            
              | 65 | 
              #		[ 'DBIProfile', profile => 2 ],  | 
            
            
              | 66 | 
              #		[ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace  | 
            
            
              | 67 | 
              #		[ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ],  | 
            
            
              | 68 | 
              	];  | 
            
            
              | 69 | 
               | 
            
            
              | 70 | 
              	# don't enable this plugin in production, since stack traces reveal too much information  | 
            
            
              | 71 | 
              	# about system to potential attackers!  | 
            
            
              | 72 | 
              	enable_if { $ENV{PLACK_DEBUG} } 'StackTrace'; | 
            
            
              | 73 | 
               | 
            
            
              | 74 | 
              	# this enables plackup or starman to serve static files and provide working plack  | 
            
            
              | 75 | 
              	# setup without need for front-end web server to serve static files  | 
            
            
              | 76 | 
              	enable_if { $ENV{INTRANETDIR} } "Plack::Middleware::Static", | 
            
            
              | 77 | 
              		path => qr{^/(intranet|opac)-tmpl/}, | 
            
            
              | 78 | 
              		root => "$ENV{INTRANETDIR}/koha-tmpl/"; | 
            
            
              | 79 | 
               | 
            
            
              | 80 | 
              	mount "/cgi-bin/koha" => $app;  | 
            
            
              | 81 | 
               | 
            
            
              | 82 | 
              };  |