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);
17 use Net::Whois::Raw qw(whois);
19 eval "use Net::Whois::Raw 0.32 qw(whois)";
22 use Business::CreditCard;
23 use String::Approx qw(amatch);
24 use Chart::LinesPoints;
25 use HTML::Widgets::SelectLayers 0.03;
26 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
27 use FS::Record qw(qsearch qsearchs fields dbdef);
29 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
30 small_custview myexit http_header);
31 use FS::Msgcat qw(gettext geterror);
32 use FS::Misc qw( send_email );
33 use FS::Report::Table::Monthly;
37 use FS::domain_record;
39 use FS::cust_bill_pay;
41 use FS::cust_credit_bill;
43 use FS::cust_main_county;
49 use FS::part_bill_event;
51 use FS::part_referral;
53 use FS::part_svc_router;
54 use FS::part_virtual_field;
57 use FS::queue qw(joblisting);
61 use FS::svc_acct_pop qw(popselector);
67 use FS::svc_broadband;
71 use FS::part_export_option;
79 $Response->AddHeader('Cache-control' => 'no-cache');
80 # $Response->AddHeader('Expires' => 0);
81 $Response->{Expires} = -36288000;
86 #print $cgi->header( '-expires' => 'now' );
87 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
88 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
90 #really should check for FS::Profiler or something
91 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
92 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
93 #should check to see it's my special version. well, switch to FS::Profiler
95 #nicked from Devel::AutoProfiler::INIT
96 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
99 SUB : while( my ($name, $ref) = each(%subs) )
101 #next if $name =~ /^(main::)?Apache::/;
102 next unless $name =~ /FS/;
103 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
110 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
111 #warn "INIT name is $name \n";
112 Devel::AutoProfiler::__instrument_sub($name, $ref);
120 my $ref = $Response->{BinaryRef};
121 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
122 #$$ref = $cgi->header() . $$ref;
123 #warn "Script_OnFlush called with dbh ". dbh. "\n";
124 #if ( dbh->can('sprintProfile') ) {
125 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
126 #warn "dbh can sprintProfile\n";
127 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
128 #warn "contenttype is sprintProfile\n";
129 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
130 or warn "can't remove";
132 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
134 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
135 "\n\n". &sprintAutoProfile(). '</PRE>';
137 $$ref .= '</BODY></HTML>';
139 dbh->{'private_profile'} = {};
143 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
144 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
145 if ( defined(@DBIx::Profile::ISA) ) {
147 #warn "enabling profiling redirects";
148 *CGI::redirect = sub {
149 my( $self, $location) = @_;
152 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
154 ( UNIVERSAL::can(dbh, 'sprintProfile')
155 ? encode_entities(dbh->sprintProfile())
156 : 'DBIx::Profile missing sprintProfile method;'.
157 'unpatched or too old?' ).
158 "\n\n". &sprintAutoProfile(). '</PRE>'.
160 dbh->{'private_profile'} = {};
168 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
171 sub sprintAutoProfile {
172 my %caller_info = %Devel::AutoProfiler::caller_info;
173 return unless keys %caller_info;
175 %Devel::AutoProfiler::caller_info = ();
177 my @keys = keys(%caller_info);
179 foreach my $key (@keys)
181 my $href = $caller_info{$key};
183 $href->{who_am_i} = $key;
186 my @subs = values(%caller_info);
188 #my @sorted = sort by_total_time ( @subs );
189 my @sorted = reverse sort by_total_time ( @subs );
191 # print Dumper \@sorted;
195 foreach my $sort (@sorted)
197 push(@readable_info, delete($sort->{who_am_i}));
198 push(@readable_info, $sort);
202 return encode_entities(Dumper(\@readable_info));
207 ( my $file = shift ) =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
208 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
209 my $ref = $Response->TrapInclude($file, @_);
213 if ( defined(@DBIx::Profile::ISA) ) {
215 #false laziness w/above
219 ${$Response->{BinaryRef}} =
221 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
223 ( UNIVERSAL::can(dbh, 'sprintProfile')
224 ? encode_entities(dbh->sprintProfile())
225 : 'DBIx::Profile missing sprintProfile method;'.
226 'unpatched or too old?' ).
227 "\n\n". &sprintAutoProfile(). '</PRE>'.
230 dbh->{'private_profile'} = {};
239 $Response->Redirect(@_);