Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: DBIx::Dump Title

by afoken (Chancellor)
on Jul 07, 2015 at 00:45 UTC ( [id://1133479]=note: print w/replies, xml ) Need Help??


in reply to Re^2: DBIx::Dump Title
in thread DBIx::Dump Title

I saw a page of documentation for DBIx::Dump that showed a "Title" parameter. I cannot find that page again.

Look at the source code of DBIx::Dump. It's a plain perl module without any XS code. About 200 lines of text, about 160 lines of code, 130 lines of code if you ignore the boilerplate. That's quite short.

Baby steps:

  • Click on the link above.
  • Note that the Module version is currently 0.04, usually translated as "quick hack, not yet stable, not yet ready for production". The fact that the documentation does not even document all supported output formats is another strong hint. Parameters for new() aren't documented at all, and neither are event handlers.
  • Click on the Source link, use your browser's search function (Ctrl-F) to search for the word "title".
  • There is no "title" in the source code.
  • So find out how DBIx::Dump creates an Excel file. Hint: The synopsis has a working example, you should look at the new() constructor and perhaps at the dump() method.
  • So, hit Ctrl-F once again, and type "new".
  • Think about what those three lines do. Hint: All arguments simply end as object attributes, without any checks.
  • "new" was not useful. Search for "dump".
  • (Did you notice that dump() DOES accept parameters, but has none in the synopsis?)
  • Think about what those four lines do. Hint: an anonymous function stored in %formats is called with all parameters passed to new() and dump(). The key for %formats is in the format attribute.
  • Remember that the synopsis hat the format attribute set to excel. So you need to find out where $formats{'excel'} is assigned to. Use Ctrl-F and type "excel" ...
  • $formats{'excel'} is initialised from $excel. You should have already seen that:
  • my $excel=sub { ... }
  • Remember how that routine is called: All attributes come in as a hash reference in the first parameter. So all parameters passed to new() and dump() are now in $self inside that routine.
  • Understand how the routine works: It calls Spreadsheet::WriteExcel->new(), then calls the addworksheet() method to create a new worksheet, then fills that worksheet using the write() method.
  • Find out how to name a new worksheet using Spreadsheet::WriteExcel. Hint: addworksheet() has optional parameters.
  • Note that the routine in $excel does not pass any parameters to addworksheet().
  • Also note that the routine calls an external routine via the eventHandler parameter, passing $self as first parameter to that callback. $self->{'Generator'} is the Spreadsheet::WriteExcel object. This allows manipulating that object.
  • (Did you notice that the eventHandler parameter must be a code reference here? The synopsis shows an EventHandler parameter (upper case "E"). That may be a typo. But EventHandler is shown to contain an array reference, not a code reference. A clear mismatch between code and documentation.)
  • Find other ways to name a worksheet. Hint: Ctrl-F "name" while reading the Spreadsheet::WriteExcel.
  • There is a worksheet method get_name(). Its documentation contains an important hint about a set_name() method:
    For reasons related to the design of Spreadsheet::WriteExcel and to the internals of Excel there is no set_name() method. The only way to set the worksheet name is via the add_worksheet() method.

So, the sad answer is that DBIx::Dump does not support setting a title for Excel dumps, not even when you hook into the code using the callback mechanism. It could, but the author did not think about that, or so it seems.

But now that you know how DBIx::Dump writes an Excel file, it should be quite obvious how to add that feature.


To me, DBIx::Dump looks quite scary. Nearly no documentation, errors in the documentation, no parameter checks, messy code. No update since 2002. I would copy the routine stored in $excel into my code, clean it up, and forget that DBIx::Dump even exists.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^4: DBIx::Dump Title
by ScottM (Initiate) on Jul 07, 2015 at 19:28 UTC
    Alexander, I don't know how to Thank You enough. That was a lot of work and documentation you created. More than what's in DBIx::Dump! It's a quick and dirty tool that will stay that way. Thanks again, Scott

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-29 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found