1 BEGIN { eval "use Devel::AutoProfiler;"; } #only if installed...
2 #BEGIN { package Devel::AutoProfiler; use vars qw(%caller_info); }
3 #use Devel::AutoProfiler;
6 use vars qw( $cgi $p );
9 #use CGI::Carp qw(fatalsToBrowser);
18 use Net::Whois::Raw qw(whois);
20 eval "use Net::Whois::Raw 0.32 qw(whois)";
24 use Spreadsheet::WriteExcel;
25 use Business::CreditCard;
26 use String::Approx qw(amatch);
27 use Chart::LinesPoints;
28 use HTML::Widgets::SelectLayers 0.03;
30 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
31 use FS::Record qw(qsearch qsearchs fields dbdef);
33 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
34 small_custview myexit http_header);
36 use FS::Msgcat qw(gettext geterror);
37 use FS::Misc qw( send_email );
38 use FS::Report::Table::Monthly;
43 use FS::domain_record;
45 use FS::cust_bill_pay;
47 use FS::cust_credit_bill;
49 use FS::cust_main_county;
55 use FS::part_bill_event;
57 use FS::part_referral;
59 use FS::part_svc_router;
60 use FS::part_virtual_field;
63 use FS::queue qw(joblisting);
67 use FS::svc_acct_pop qw(popselector);
73 use FS::svc_broadband;
77 use FS::part_export_option;
85 $Response->AddHeader('Cache-control' => 'no-cache');
86 # $Response->AddHeader('Expires' => 0);
87 $Response->{Expires} = -36288000;
92 #print $cgi->header( '-expires' => 'now' );
93 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
94 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
96 #really should check for FS::Profiler or something
97 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
98 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
99 #should check to see it's my special version. well, switch to FS::Profiler
101 #nicked from Devel::AutoProfiler::INIT
102 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
105 SUB : while( my ($name, $ref) = each(%subs) )
107 #next if $name =~ /^(main::)?Apache::/;
108 next unless $name =~ /FS/;
109 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
116 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
117 #warn "INIT name is $name \n";
118 Devel::AutoProfiler::__instrument_sub($name, $ref);
126 my $ref = $Response->{BinaryRef};
127 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
128 #$$ref = $cgi->header() . $$ref;
129 #warn "Script_OnFlush called with dbh ". dbh. "\n";
130 #if ( dbh->can('sprintProfile') ) {
131 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
132 #warn "dbh can sprintProfile\n";
133 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
134 #warn "contenttype is sprintProfile\n";
135 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
136 or warn "can't remove";
138 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
140 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
141 "\n\n". &sprintAutoProfile(). '</PRE>';
143 $$ref .= '</BODY></HTML>';
145 dbh->{'private_profile'} = {};
149 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
150 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
151 if ( defined(@DBIx::Profile::ISA) ) {
153 #warn "enabling profiling redirects";
154 *CGI::redirect = sub {
155 my( $self, $location) = @_;
158 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
160 ( UNIVERSAL::can(dbh, 'sprintProfile')
161 ? encode_entities(dbh->sprintProfile())
162 : 'DBIx::Profile missing sprintProfile method;'.
163 'unpatched or too old?' ).
164 "\n\n". &sprintAutoProfile(). '</PRE>'.
166 dbh->{'private_profile'} = {};
174 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
177 sub sprintAutoProfile {
178 my %caller_info = %Devel::AutoProfiler::caller_info;
179 return unless keys %caller_info;
181 %Devel::AutoProfiler::caller_info = ();
183 my @keys = keys(%caller_info);
185 foreach my $key (@keys)
187 my $href = $caller_info{$key};
189 $href->{who_am_i} = $key;
192 my @subs = values(%caller_info);
194 #my @sorted = sort by_total_time ( @subs );
195 my @sorted = reverse sort by_total_time ( @subs );
197 # print Dumper \@sorted;
201 foreach my $sort (@sorted)
203 push(@readable_info, delete($sort->{who_am_i}));
204 push(@readable_info, $sort);
208 return encode_entities(Dumper(\@readable_info));
215 if ( $file =~ m(^([^/].*)/[^/]+) ) {
216 unshift @{$Response->{asp}{includes_dir}}, "./$1";
219 $file =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
220 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
221 my $ref = $Response->TrapInclude($file, @_);
222 shift @{$Response->{asp}{includes_dir}} if $shift;
226 if ( defined(@DBIx::Profile::ISA) ) {
228 #false laziness w/above
232 ${$Response->{BinaryRef}} =
234 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
236 ( UNIVERSAL::can(dbh, 'sprintProfile')
237 ? encode_entities(dbh->sprintProfile())
238 : 'DBIx::Profile missing sprintProfile method;'.
239 'unpatched or too old?' ).
240 "\n\n". &sprintAutoProfile(). '</PRE>'.
243 dbh->{'private_profile'} = {};
252 $Response->Redirect(@_);