[dancer-users] dancer1 and DBIx: can I modify the returned result in a view?

John Stoffel john at stoffel.org
Mon Jul 19 17:16:43 EDT 2021


Hi all,
I'm tasked with hacking an old Dancer1 app I wrote back in 2014/2015
which basically just returns from results from a DB query.  One of the
fields is called 'url' and I need to tweak it, since the URL in the DB
is completely wrong.

I've tried poking at it in my views/search.tt file, but I can't figure
out the right syntax to make it work.  My results loop looks like
this:

  <% IF results.size %>
      Results (found <% results.size %> matches):
      <ul>
        <% FOREACH result IN results %>
         <li><% result.full_name.replace("((?i)$tobold)",'<b>$1</b>') %>
            <ul>
	       <% FOREACH a IN result.account %>
	         <li><a href="<% a.url() %>" target="_blank">
                   Account # <% a.account_number  %>,
                   <% IF a.volume() %> Volume: <% a.volume() %>, <% END %>
                   <% IF a.box() %> Box: <% a.box() %>, <% END %>
                   <% IF a.folder() %> Folder: <% a.folder() %>, <% END %>
                  <% IF a.range() %> Range: <% a.range() %> <% END %>
		  </a> <% newurl %><br>
	      <% END %>
	  </ul>
       <% END %>



And I need to pull out the a.url, do some manipulations on it, then
display it.  I tried doing:

     	       <% FOREACH a IN result.account %>

	         <% a.url =
	         a.url.replace("http://gigi.mwa.org/netpub/server.np",
	         "https://gigi.mwa.org/imagearchive/filename/") %>
		 
	         <li><a href="<% a.url() %>" target="_blank">
                   Account # <% a.account_number  %>,
                   <% IF a.volume() %> Volume: <% a.volume() %>, <% END %>
                   <% IF a.box() %> Box: <% a.box() %>, <% END %>
                   <% IF a.folder() %> Folder: <% a.folder() %>, <% END %>
                  <% IF a.range() %> Range: <% a.range() %> <% END %>
		  </a> <% newurl %><br>
	      <% END %>
	  </ul>

But that didn't seem to work.  Should I be doing this search and
replace in the lib/Foo.pm file in the _perform_search function
instead?  And if so, how do I deal with the DBIx resultset properly so
I can loop through and update these URLs?

I really don't want to have to do this in SQL somewhere, though I
guess I could be convinced to do this hack until the DB itself is
updated.

Thanks,
John


More information about the dancer-users mailing list