Author: timbo
Date: Thu Mar 13 07:29:07 2008
New Revision: 10916

Modified:
   dbi/trunk/Changes
   dbi/trunk/DBI.xs
   dbi/trunk/lib/DBI/Profile.pm
   dbi/trunk/t/40profile.t

Log:
Changed dbi_profile() to accept a hash of profiles and apply to all.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Thu Mar 13 07:29:07 2008
@@ -42,6 +42,8 @@
 
 =head2 Changes in DBI 1.603
 
+Fix occasional errors reported via cpan testers
+
   Fixed pure-perl fetchall_arrayref with $max_rows argument
     to not error when fetching after all rows already fetched.
     (Was fixed for compiled drivers back in DBI 1.31.)
@@ -49,6 +51,7 @@
   Fixed C sprintf formats and casts, fixing compiler warnings.
 
   Changed gofer stream transport to improve error reporting.
+  Changed dbi_profile() to accept a hash of profiles and apply to all.
 
   Added options to t/85gofer.t so it's more useful for manual testing.
 

Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Thu Mar 13 07:29:07 2008
@@ -746,7 +746,8 @@
 
 static SV *
 dbih_inner(pTHX_ SV *orv, const char *what)
-{   /* convert outer to inner handle else croak(what) if what is not null */
+{   /* convert outer to inner handle else croak(what) if what is not NULL */
+    /* if what is NULL then return NULL for invalid handles */
     dPERINTERP;
     MAGIC *mg;
     SV *ohv;           /* outer HV after derefing the RV       */
@@ -766,6 +767,8 @@
        croak("%s handle %s is not a DBI handle", what, neatsvpv(orv,0));
     }
     if (!SvMAGICAL(ohv)) {
+       if (!what)
+           return NULL;
        sv_dump(orv);
        croak("%s handle %s is not a DBI handle (has no magic)",
                what, neatsvpv(orv,0));
@@ -4174,22 +4177,38 @@
     NV t1
     NV t2
     CODE:
-    D_imp_xxh(h);
-    SV *leaf = dbi_profile(h, imp_xxh, statement,
-       SvROK(method) ? SvRV(method) : method,
-       t1, t2
-    );
-    if (DBIc_TRACE_LEVEL(imp_xxh) >= 9)
-        warn("dbi_profile(%s, %s, %f, %f) =%s, gimme=%ld",
-                neatsvpv(statement,0), neatsvpv(method,0), t1, t2,
-                neatsvpv(leaf,0), (long)GIMME_V);
+    SV *leaf = &sv_undef;
     (void)cv;   /* avoid unused var warnings */
+    if (SvROK(method))
+        method = SvRV(method);
+    if (dbih_inner(aTHX_ h, NULL)) {    /* is a DBI handle */
+        D_imp_xxh(h);
+        leaf = dbi_profile(h, imp_xxh, statement, method, t1, t2);
+    }
+    else if (SvROK(h) && SvTYPE(SvRV(h)) == SVt_PVHV) {
+        /* iterate over values %$h */
+        HV *hv = (HV*)SvRV(h);
+        SV *tmp;
+       char *key;
+       I32 keylen = 0;
+       hv_iterinit(hv);
+       while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
+            if (SvOK(tmp)) {
+                D_imp_xxh(tmp);
+                leaf = dbi_profile(tmp, imp_xxh, statement, method, t1, t2);
+            }
+       };
+    }
+    else {
+        croak("dbi_profile(%s,...) invalid handle argument", neatsvpv(h,0));
+    }
     if (GIMME_V == G_VOID)
         ST(0) = &sv_undef;  /* skip sv_mortalcopy if not needed */
     else
         ST(0) = sv_mortalcopy(leaf);
 
 
+
 SV *
 dbi_profile_merge_nodes(dest, ...)
     SV * dest

Modified: dbi/trunk/lib/DBI/Profile.pm
==============================================================================
--- dbi/trunk/lib/DBI/Profile.pm        (original)
+++ dbi/trunk/lib/DBI/Profile.pm        Thu Mar 13 07:29:07 2008
@@ -612,11 +612,10 @@
 The $h->{Profile}{Path} attribute is processed by dbi_profile() in
 the usual way.
 
-It is recommended that you keep these extra data samples separate
-from the DBI profile data samples by using values for $statement
-and $method that are distinct from any that are likely to appear
-in the profile data normally.
-
+The $h parameter is usually a DBI handle but it can also be a reference to a
+hash, in which case the dbi_profile() acts on each defined value in the hash.
+This is an efficient way to update multiple profiles with a single sample,
+and is used by the L<DashProfiler> module.
 
 =head1 SUBCLASSING
 

Modified: dbi/trunk/t/40profile.t
==============================================================================
--- dbi/trunk/t/40profile.t     (original)
+++ dbi/trunk/t/40profile.t     Thu Mar 13 07:29:07 2008
@@ -306,7 +306,7 @@
 ];
 $dbh->{Profile}->{Data} = undef;
 $sql = qq{insert into foo20060726 (a,b) values (42,"foo")};
-dbi_profile($dbh, $sql, 'mymethod', 100000000, 100000002);
+dbi_profile( { foo => $dbh, bar => undef }, $sql, 'mymethod', 100000000, 
100000002);
 $tmp = $dbh->{Profile}{Data};
 #warn Dumper($tmp);
 is_deeply $tmp, {

Reply via email to