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);
21 use Net::Whois::Raw qw(whois);
23 eval "use Net::Whois::Raw 0.32 qw(whois)";
27 use Spreadsheet::WriteExcel;
28 use Business::CreditCard;
29 use String::Approx qw(amatch);
30 use Chart::LinesPoints;
31 use HTML::Widgets::SelectLayers 0.05;
33 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
34 use FS::Record qw(qsearch qsearchs fields dbdef);
36 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
37 small_custview myexit http_header);
39 use FS::Msgcat qw(gettext geterror);
40 use FS::Misc qw( send_email );
41 use FS::Report::Table::Monthly;
46 use FS::domain_record;
48 use FS::cust_bill_pay;
50 use FS::cust_credit_bill;
51 use FS::cust_main qw(smart_search);
52 use FS::cust_main_county;
58 use FS::part_bill_event;
60 use FS::part_referral;
62 use FS::part_svc_router;
63 use FS::part_virtual_field;
66 use FS::queue qw(joblisting);
70 use FS::svc_acct_pop qw(popselector);
76 use FS::svc_broadband;
80 use FS::part_export_option;
86 use FS::payment_gateway;
87 use FS::agent_payment_gateway;
90 $Response->AddHeader('Cache-control' => 'no-cache');
91 # $Response->AddHeader('Expires' => 0);
92 $Response->{Expires} = -36288000;
97 #print $cgi->header( '-expires' => 'now' );
98 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
99 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
101 #really should check for FS::Profiler or something
102 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
103 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
104 #should check to see it's my special version. well, switch to FS::Profiler
106 #nicked from Devel::AutoProfiler::INIT
107 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
110 SUB : while( my ($name, $ref) = each(%subs) )
112 #next if $name =~ /^(main::)?Apache::/;
113 next unless $name =~ /FS/;
114 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
121 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
122 #warn "INIT name is $name \n";
123 Devel::AutoProfiler::__instrument_sub($name, $ref);
131 my $ref = $Response->{BinaryRef};
132 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
133 #$$ref = $cgi->header() . $$ref;
134 #warn "Script_OnFlush called with dbh ". dbh. "\n";
135 #if ( dbh->can('sprintProfile') ) {
136 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
137 #warn "dbh can sprintProfile\n";
138 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
139 #warn "contenttype is sprintProfile\n";
140 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
141 or warn "can't remove";
143 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
145 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
146 "\n\n". &sprintAutoProfile(). '</PRE>';
148 $$ref .= '</BODY></HTML>';
150 dbh->{'private_profile'} = {};
154 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
155 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
156 if ( defined(@DBIx::Profile::ISA) ) {
158 #warn "enabling profiling redirects";
159 *CGI::redirect = sub {
160 my( $self, $location) = @_;
163 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
165 ( UNIVERSAL::can(dbh, 'sprintProfile')
166 ? encode_entities(dbh->sprintProfile())
167 : 'DBIx::Profile missing sprintProfile method;'.
168 'unpatched or too old?' ).
169 "\n\n". &sprintAutoProfile(). '</PRE>'.
171 dbh->{'private_profile'} = {};
179 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
182 sub sprintAutoProfile {
183 my %caller_info = %Devel::AutoProfiler::caller_info;
184 return unless keys %caller_info;
186 %Devel::AutoProfiler::caller_info = ();
188 my @keys = keys(%caller_info);
190 foreach my $key (@keys)
192 my $href = $caller_info{$key};
194 $href->{who_am_i} = $key;
197 my @subs = values(%caller_info);
199 #my @sorted = sort by_total_time ( @subs );
200 my @sorted = reverse sort by_total_time ( @subs );
202 # print Dumper \@sorted;
206 foreach my $sort (@sorted)
208 push(@readable_info, delete($sort->{who_am_i}));
209 push(@readable_info, $sort);
213 return encode_entities(Dumper(\@readable_info));
220 if ( $file =~ m(^([^/].*)/[^/]+) ) {
221 unshift @{$Response->{asp}{includes_dir}}, "./$1";
224 $file =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
225 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
226 my $ref = $Response->TrapInclude($file, @_);
227 shift @{$Response->{asp}{includes_dir}} if $shift;
231 if ( defined(@DBIx::Profile::ISA) ) {
233 #false laziness w/above
237 ${$Response->{BinaryRef}} =
239 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
241 ( UNIVERSAL::can(dbh, 'sprintProfile')
242 ? encode_entities(dbh->sprintProfile())
243 : 'DBIx::Profile missing sprintProfile method;'.
244 'unpatched or too old?' ).
245 "\n\n". &sprintAutoProfile(). '</PRE>'.
248 dbh->{'private_profile'} = {};
257 $Response->Redirect(@_);