Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Evaluating subroutines from within data

by graff (Chancellor)
on Jan 07, 2012 at 04:20 UTC ( #946713=note: print w/replies, xml ) Need Help??

in reply to Evaluating subroutines from within data

If you really think you "need to insert another subroutine into the data", then you should think seriously about refactoring your app to use a real templating system. I've used Template::Toolkit to good effect (despite a daunting array of documentation), though maybe you'd prefer something simpler like HTML::Template.

I'm pretty sure there are other template systems as well. The whole point is that they support the idea of allowing "text data" (the template) to function as code when you want it to.

If I understand your description, you'd like to have a "definition list" stored in one file, and then have one line in the data for a given page that will simply incorporate the def.list at a chosen point. That's one of the nice things that a template system will do very easily. (Other things you might like include loops and conditionals, all tied up in a format that still ends up looking a lot like the actual document structure that defines your page layout.)

Maybe the amount of refactoring you'd have to do to switch whole-hog to a template system is more work that you want to do, which would be a shame, because it's not clear that carrying on in your current direction, without a template system, will be any less arduous.

I actually think there's a good chance that you can try a simpler template system just for this one (class of) page layout(s) that you're struggling with, and not break the rest of your app. Then you can gradually expand your use of templates as you continue to grow and update the app.

  • Comment on Re: Evaluating subroutines from within data

Replies are listed 'Best First'.
Re^2: Evaluating subroutines from within data
by Lady_Aleena (Curate) on Jan 07, 2012 at 06:44 UTC

    graff, I have looked at both of those modules, and neither would do the templating I need for my site. I have yet to find anything that will insert a bunch of code before the main body of the page and another bunch of code at the end of the main body of the page to my specifications. Also, I keep all of my data stored in pipe delineated text files. I've put a sample of what I want to do in my reply to the anonymous monk above.

    If you want to see start_html and end_html, let me know; I'll put it on my scratchpad for you to look at.

    Have a cookie and a very nice day!
    Lady Aleena

        Are you saying that I'd have to break up all of my modules and put the subroutines into their own files with a .tt extension? So, I'd have to break up my Base::HTML where most of the base code for my site lives?

        Have a cookie and a very nice day!
        Lady Aleena

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://946713]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2018-06-19 03:57 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.