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);
19 use Net::Whois::Raw qw(whois);
21 eval "use Net::Whois::Raw 0.32 qw(whois)";
25 use Spreadsheet::WriteExcel;
26 use Business::CreditCard;
27 use String::Approx qw(amatch);
28 use Chart::LinesPoints;
29 use HTML::Widgets::SelectLayers 0.03;
31 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
32 use FS::Record qw(qsearch qsearchs fields dbdef);
34 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
35 small_custview myexit http_header);
37 use FS::Msgcat qw(gettext geterror);
38 use FS::Misc qw( send_email );
39 use FS::Report::Table::Monthly;
44 use FS::domain_record;
46 use FS::cust_bill_pay;
48 use FS::cust_credit_bill;
50 use FS::cust_main_county;
56 use FS::part_bill_event;
58 use FS::part_referral;
60 use FS::part_svc_router;
61 use FS::part_virtual_field;
64 use FS::queue qw(joblisting);
68 use FS::svc_acct_pop qw(popselector);
74 use FS::svc_broadband;
78 use FS::part_export_option;
86 $Response->AddHeader('Cache-control' => 'no-cache');
87 # $Response->AddHeader('Expires' => 0);
88 $Response->{Expires} = -36288000;
93 #print $cgi->header( '-expires' => 'now' );
94 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
95 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
97 #really should check for FS::Profiler or something
98 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
99 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
100 #should check to see it's my special version. well, switch to FS::Profiler
102 #nicked from Devel::AutoProfiler::INIT
103 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
106 SUB : while( my ($name, $ref) = each(%subs) )
108 #next if $name =~ /^(main::)?Apache::/;
109 next unless $name =~ /FS/;
110 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
117 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
118 #warn "INIT name is $name \n";
119 Devel::AutoProfiler::__instrument_sub($name, $ref);
127 my $ref = $Response->{BinaryRef};
128 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
129 #$$ref = $cgi->header() . $$ref;
130 #warn "Script_OnFlush called with dbh ". dbh. "\n";
131 #if ( dbh->can('sprintProfile') ) {
132 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
133 #warn "dbh can sprintProfile\n";
134 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
135 #warn "contenttype is sprintProfile\n";
136 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
137 or warn "can't remove";
139 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
141 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
142 "\n\n". &sprintAutoProfile(). '</PRE>';
144 $$ref .= '</BODY></HTML>';
146 dbh->{'private_profile'} = {};
150 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
151 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
152 if ( defined(@DBIx::Profile::ISA) ) {
154 #warn "enabling profiling redirects";
155 *CGI::redirect = sub {
156 my( $self, $location) = @_;
159 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
161 ( UNIVERSAL::can(dbh, 'sprintProfile')
162 ? encode_entities(dbh->sprintProfile())
163 : 'DBIx::Profile missing sprintProfile method;'.
164 'unpatched or too old?' ).
165 "\n\n". &sprintAutoProfile(). '</PRE>'.
167 dbh->{'private_profile'} = {};
175 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
178 sub sprintAutoProfile {
179 my %caller_info = %Devel::AutoProfiler::caller_info;
180 return unless keys %caller_info;
182 %Devel::AutoProfiler::caller_info = ();
184 my @keys = keys(%caller_info);
186 foreach my $key (@keys)
188 my $href = $caller_info{$key};
190 $href->{who_am_i} = $key;
193 my @subs = values(%caller_info);
195 #my @sorted = sort by_total_time ( @subs );
196 my @sorted = reverse sort by_total_time ( @subs );
198 # print Dumper \@sorted;
202 foreach my $sort (@sorted)
204 push(@readable_info, delete($sort->{who_am_i}));
205 push(@readable_info, $sort);
209 return encode_entities(Dumper(\@readable_info));
216 if ( $file =~ m(^([^/].*)/[^/]+) ) {
217 unshift @{$Response->{asp}{includes_dir}}, "./$1";
220 $file =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
221 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
222 my $ref = $Response->TrapInclude($file, @_);
223 shift @{$Response->{asp}{includes_dir}} if $shift;
227 if ( defined(@DBIx::Profile::ISA) ) {
229 #false laziness w/above
233 ${$Response->{BinaryRef}} =
235 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
237 ( UNIVERSAL::can(dbh, 'sprintProfile')
238 ? encode_entities(dbh->sprintProfile())
239 : 'DBIx::Profile missing sprintProfile method;'.
240 'unpatched or too old?' ).
241 "\n\n". &sprintAutoProfile(). '</PRE>'.
244 dbh->{'private_profile'} = {};
253 $Response->Redirect(@_);