Author: timbo
Date: Thu Mar 22 08:08:34 2007
New Revision: 9294

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

Log:
Added support for DBI Profile Path to contain refs to scalars which will be 
de-ref'd for each profile sample.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Thu Mar 22 08:08:34 2007
@@ -39,6 +39,8 @@
 
   Added support for install_methods to DBD::Gofer.
   Added goferperf.pl utility (doesn't get installed).
+  Added support for DBI Profile Path to contain refs to scalars
+    which will be de-ref'd for each profile sample.
 
 =head2 Changes in DBI 1.54 (svn rev 9157),  23rd February 2007
 

Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Thu Mar 22 08:08:34 2007
@@ -2426,6 +2426,11 @@
                 if (items == -2) /* this profile data was vetoed */
                     return;
            }
+            else if (SvROK(pathsv)) {
+                /* only meant for refs to scalars currently */
+                const char *p = SvPV_nolen(SvRV(pathsv));
+                dest_node = _profile_next_node(dest_node, p);
+            }
            else if (SvOK(pathsv)) {
                STRLEN len;
                 const char *p = SvPV(pathsv,len);

Modified: dbi/trunk/lib/DBI/Profile.pm
==============================================================================
--- dbi/trunk/lib/DBI/Profile.pm        (original)
+++ dbi/trunk/lib/DBI/Profile.pm        Thu Mar 22 08:08:34 2007
@@ -97,7 +97,7 @@
 entry in the Data to be the name of the method that was called.
 For example, if the Path was:
 
-  [ 'foo', '!MethodName', 'selectall_arrayref' ]
+  [ 'foo', '!MethodName', 'bar' ]
 
 and the selectall_arrayref() method was called, then the profile sample data
 for that call will be merged into the tree at:
@@ -313,6 +313,12 @@
 value of the corresponding database handle attribute should be used at that
 point in the Path.
 
+=item Reference to a Scalar
+
+Specifies that the current value of the referenced scalar be used at that point
+in the Path.  This provides an efficient way to get 'contextual' values into
+your profile.
+
 =item Other Values
 
 Any other values are stringified and used literally.

Modified: dbi/trunk/t/40profile.t
==============================================================================
--- dbi/trunk/t/40profile.t     (original)
+++ dbi/trunk/t/40profile.t     Thu Mar 22 08:08:34 2007
@@ -183,15 +183,17 @@
 
 # 
-----------------------------------------------------------------------------------
 
-# try statement and method name path
+# try statement and method name and reference-to-scalar path
+my $by_reference = 'foo';
 $dbh = DBI->connect("dbi:ExampleP:", 'usrnam', '', {
     RaiseError => 1,
-    Profile => { Path => [ '{Username}', '!Statement', 'foo', '!MethodName' ] }
+    Profile => { Path => [ '{Username}', '!Statement', \$by_reference, 
'!MethodName' ] }
 });
 $sql = "select name from .";
 $sth = $dbh->prepare($sql);
 $sth->execute();
 $sth->fetchrow_hashref;
+$by_reference = 'bar';
 $sth->finish;
 undef $sth; # DESTROY
 
@@ -199,8 +201,9 @@
 ok $tmp->{Data}{usrnam}{""}{foo}{STORE};
 $tmp->{Data}{usrnam}{""}{foo} = {};
 # make test insentitive to number of local files
+#warn Dumper($tmp);
 is_deeply $tmp, bless {
-    'Path' => [ '{Username}', '!Statement', 'foo', '!MethodName' ],
+    'Path' => [ '{Username}', '!Statement', \$by_reference, '!MethodName' ],
     'Data' => {
         '' => { # because Profile was enabled by DBI just before Username was 
set
             '' => {
@@ -217,8 +220,10 @@
                    'foo' => {
                        'execute' => [ 1, 0, 0, 0, 0, 0, 0 ],
                        'fetchrow_hashref' => [ 1, 0, 0, 0, 0, 0, 0 ],
-                       'DESTROY' => [ 1, 0, 0, 0, 0, 0, 0 ],
                        'prepare' => [ 1, 0, 0, 0, 0, 0, 0 ],
+                   },
+                   'bar' => {
+                       'DESTROY' => [ 1, 0, 0, 0, 0, 0, 0 ],
                        'finish' => [ 1, 0, 0, 0, 0, 0, 0 ],
                    },
            },
@@ -226,6 +231,7 @@
     },
 } => 'DBI::Profile';
 
+
 $dbh->{Profile}->{Path} = [ '!File', '!File2', '!Caller', '!Caller2' ];
 $dbh->{Profile}->{Data} = undef;
 

Reply via email to