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;
27 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
28 use FS::Record qw(qsearch qsearchs fields dbdef);
30 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
31 small_custview myexit http_header);
32 use FS::Msgcat qw(gettext geterror);
33 use FS::Misc qw( send_email );
34 use FS::Report::Table::Monthly;
38 use FS::domain_record;
40 use FS::cust_bill_pay;
42 use FS::cust_credit_bill;
44 use FS::cust_main_county;
50 use FS::part_bill_event;
52 use FS::part_referral;
54 use FS::part_svc_router;
55 use FS::part_virtual_field;
58 use FS::queue qw(joblisting);
62 use FS::svc_acct_pop qw(popselector);
68 use FS::svc_broadband;
72 use FS::part_export_option;
80 $Response->AddHeader('Cache-control' => 'no-cache');
81 # $Response->AddHeader('Expires' => 0);
82 $Response->{Expires} = -36288000;
87 #print $cgi->header( '-expires' => 'now' );
88 #dbh->{'private_profile'} = {} if dbh->can('sprintProfile');
89 dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
91 #really should check for FS::Profiler or something
92 # Devel::AutoProfiler _our_ VERSION? thanks a fucking lot
93 if ( Devel::AutoProfiler->can('__recursively_fetch_subs_in_package') ) {
94 #should check to see it's my special version. well, switch to FS::Profiler
96 #nicked from Devel::AutoProfiler::INIT
97 my %subs = Devel::AutoProfiler::__recursively_fetch_subs_in_package('main');
100 SUB : while( my ($name, $ref) = each(%subs) )
102 #next if $name =~ /^(main::)?Apache::/;
103 next unless $name =~ /FS/;
104 foreach my $sub (@Devel::AutoProfiler::do_not_instrument_this_sub)
111 next if ($Devel::AutoProfiler::do_not_instrument_this_sub{$name});
112 #warn "INIT name is $name \n";
113 Devel::AutoProfiler::__instrument_sub($name, $ref);
121 my $ref = $Response->{BinaryRef};
122 #$$ref = $cgi->header( @FS::CGI::header ) . $$ref;
123 #$$ref = $cgi->header() . $$ref;
124 #warn "Script_OnFlush called with dbh ". dbh. "\n";
125 #if ( dbh->can('sprintProfile') ) {
126 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
127 #warn "dbh can sprintProfile\n";
128 if ( lc($Response->{ContentType}) eq 'text/html' ) { #con
129 #warn "contenttype is sprintProfile\n";
130 $$ref =~ s/<\/BODY>[\s\n]*<\/HTML>[\s\n]*$//i
131 or warn "can't remove";
133 #$$ref .= '<PRE>'. ("\n"x96). encode_entities(dbh->sprintProfile()). '</PRE>';
135 $$ref .= '<PRE>'. ("\n"x4096). encode_entities(dbh->sprintProfile()).
136 "\n\n". &sprintAutoProfile(). '</PRE>';
138 $$ref .= '</BODY></HTML>';
140 dbh->{'private_profile'} = {};
144 #if ( defined(@DBIx::Profile::ISA) && DBIx::Profile::db->can('sprintProfile') ) {
145 #if ( defined(@DBIx::Profile::ISA) && UNIVERSAL::can('DBIx::Profile::db', 'sprintProfile') ) {
146 if ( defined(@DBIx::Profile::ISA) ) {
148 #warn "enabling profiling redirects";
149 *CGI::redirect = sub {
150 my( $self, $location) = @_;
153 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
155 ( UNIVERSAL::can(dbh, 'sprintProfile')
156 ? encode_entities(dbh->sprintProfile())
157 : 'DBIx::Profile missing sprintProfile method;'.
158 'unpatched or too old?' ).
159 "\n\n". &sprintAutoProfile(). '</PRE>'.
161 dbh->{'private_profile'} = {};
169 return $a->{total_time_in_sub} <=> $b->{total_time_in_sub};
172 sub sprintAutoProfile {
173 my %caller_info = %Devel::AutoProfiler::caller_info;
174 return unless keys %caller_info;
176 %Devel::AutoProfiler::caller_info = ();
178 my @keys = keys(%caller_info);
180 foreach my $key (@keys)
182 my $href = $caller_info{$key};
184 $href->{who_am_i} = $key;
187 my @subs = values(%caller_info);
189 #my @sorted = sort by_total_time ( @subs );
190 my @sorted = reverse sort by_total_time ( @subs );
192 # print Dumper \@sorted;
196 foreach my $sort (@sorted)
198 push(@readable_info, delete($sort->{who_am_i}));
199 push(@readable_info, $sort);
203 return encode_entities(Dumper(\@readable_info));
208 ( my $file = shift ) =~ s(^/)(%%%FREESIDE_DOCUMENT_ROOT%%%/);
209 #broken in 5.005# ${$Response->TrapInclude($file, @_)};
210 my $ref = $Response->TrapInclude($file, @_);
214 if ( defined(@DBIx::Profile::ISA) ) {
216 #false laziness w/above
220 ${$Response->{BinaryRef}} =
222 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
224 ( UNIVERSAL::can(dbh, 'sprintProfile')
225 ? encode_entities(dbh->sprintProfile())
226 : 'DBIx::Profile missing sprintProfile method;'.
227 'unpatched or too old?' ).
228 "\n\n". &sprintAutoProfile(). '</PRE>'.
231 dbh->{'private_profile'} = {};
240 $Response->Redirect(@_);