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);
20 use Net::Whois::Raw qw(whois);
22 eval "use Net::Whois::Raw 0.32 qw(whois)";
26 use Spreadsheet::WriteExcel;
27 use Business::CreditCard;
28 use String::Approx qw(amatch);
29 use Chart::LinesPoints;
30 use HTML::Widgets::SelectLayers 0.05;
32 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
33 use FS::Record qw(qsearch qsearchs fields dbdef);
35 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
36 small_custview myexit http_header);
38 use FS::Msgcat qw(gettext geterror);
39 use FS::Misc qw( send_email );
40 use FS::Report::Table::Monthly;
45 use FS::domain_record;
47 use FS::cust_bill_pay;
49 use FS::cust_credit_bill;
51 use FS::cust_main_county;
57 use FS::part_bill_event;
59 use FS::part_referral;
61 use FS::part_svc_router;
62 use FS::part_virtual_field;
65 use FS::queue qw(joblisting);
69 use FS::svc_acct_pop qw(popselector);
75 use FS::svc_broadband;
79 use FS::part_export_option;
85 use FS::payment_gateway;
86 use FS::agent_payment_gateway;
89 $Response->AddHeader('Cache-control' => 'no-cache');
90 # $Response->AddHeader('Expires' => 0);
91 $Response->{Expires} = -36288000;
96 #print $cgi->header( '-expires' => 'now' );
97 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
98 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
100 #really should check for FS::Profiler or something
101 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
102 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
103 #should check to see it's my special version. well, switch to FS::Profiler
105 #nicked from Devel::AutoProfiler::INIT
106 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
109 SUB : while( my ($name, $ref) = each(%subs) )
111 #next if $name =~ /^(main::)?Apache::/;
112 next unless $name =~ /FS/;
113 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
120 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
121 #warn "INIT name is $name \n";
122 Devel::AutoProfiler::__instrument_sub($name, $ref);
130 my $ref = $Response->{BinaryRef};
131 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
132 #$$ref = $cgi->header() . $$ref;
133 #warn "Script_OnFlush called with dbh ". dbh. "\n";
134 #if ( dbh->can('sprintProfile') ) {
135 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
136 #warn "dbh can sprintProfile\n";
137 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
138 #warn "contenttype is sprintProfile\n";
139 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
140 or warn "can't remove";
142 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
144 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
145 "\n\n". &sprintAutoProfile(). '</PRE>';
147 $$ref .= '</BODY></HTML>';
149 dbh->{'private_profile'} = {};
153 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
154 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
155 if ( defined(@DBIx::Profile::ISA) ) {
157 #warn "enabling profiling redirects";
158 *CGI::redirect = sub {
159 my( $self, $location) = @_;
162 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
164 ( UNIVERSAL::can(dbh, 'sprintProfile')
165 ? encode_entities(dbh->sprintProfile())
166 : 'DBIx::Profile missing sprintProfile method;'.
167 'unpatched or too old?' ).
168 "\n\n". &sprintAutoProfile(). '</PRE>'.
170 dbh->{'private_profile'} = {};
178 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
181 sub sprintAutoProfile {
182 my %caller_info = %Devel::AutoProfiler::caller_info;
183 return unless keys %caller_info;
185 %Devel::AutoProfiler::caller_info = ();
187 my @keys = keys(%caller_info);
189 foreach my $key (@keys)
191 my $href = $caller_info{$key};
193 $href->{who_am_i} = $key;
196 my @subs = values(%caller_info);
198 #my @sorted = sort by_total_time ( @subs );
199 my @sorted = reverse sort by_total_time ( @subs );
201 # print Dumper \@sorted;
205 foreach my $sort (@sorted)
207 push(@readable_info, delete($sort->{who_am_i}));
208 push(@readable_info, $sort);
212 return encode_entities(Dumper(\@readable_info));
219 if ( $file =~ m(^([^/].*)/[^/]+) ) {
220 unshift @{$Response->{asp}{includes_dir}}, "./$1";
223 $file =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
224 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
225 my $ref = $Response->TrapInclude($file, @_);
226 shift @{$Response->{asp}{includes_dir}} if $shift;
230 if ( defined(@DBIx::Profile::ISA) ) {
232 #false laziness w/above
236 ${$Response->{BinaryRef}} =
238 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
240 ( UNIVERSAL::can(dbh, 'sprintProfile')
241 ? encode_entities(dbh->sprintProfile())
242 : 'DBIx::Profile missing sprintProfile method;'.
243 'unpatched or too old?' ).
244 "\n\n". &sprintAutoProfile(). '</PRE>'.
247 dbh->{'private_profile'} = {};
256 $Response->Redirect(@_);