Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^10: RFC: Proofread the POD for my HTML elements module

by Don Coyote (Pilgrim)
on May 03, 2013 at 10:05 UTC ( #1031851=note: print w/replies, xml ) Need Help??

in reply to Re^9: RFC: Proofread the POD for my HTML elements module
in thread RFC: Proofread the POD for my HTML elements module

i have removed the tabs, and on test running discovered a bigger problem

using the synopsis example provided, You can clearly see that html passes a tab value, and then a CODEREF. However the html function itself expects two values. And proceeds to behave as if no coderef was even passed to it.

As this is a major obstacle, going beyond the implementation of tab indentation, I think it would be a good idea to get your take on this. Did your synopsis run through the module ok for you?

short while passes...

Ok I just saw your thread on coderefs, so you are aware of this. The solutions provided are fairly robust. I have also been thinking about alternate approaches.

What though is the problem? At this stage I see the 'problem' to be twofold.

  1. HTML is being programmatically produced
  2. What are you doing differently to existing modules?

The first point is something that I keep getting told is the most relevantissue, so should be borne in mind throughout the process. Is this module necessary, does HTML require to be programmatically produced etc..

The second point underlies what i think is the main source of bafflement in this task. Why? are you passing coderefs?

And how would the module provide an advantage to a user over staticly writing HTML? Or more appropriately, using an existing module?

I think the issue to confront is, what does the user want to do, and what does the module provide. I have some thoughts inspired by hacking on your module, and from experience of HTML production. I think they could tie in easily at this stage, to produce something simpler.

To start with, every module i see so far seems to treat the HEAD's elements as only needing one function. Yet BODY's children all get their own functions.

And so on, HTML as a function, recieving HEAD and BODY as its arguments. Each, recursing into each childs elements function or parameters intil a swamp of refs consume all. If this is to be a functional module why not keep it functional?

  • Comment on Re^10: RFC: Proofread the POD for my HTML elements module

Replies are listed 'Best First'.
Re^11: RFC: Proofread the POD for my HTML elements module
by Lady_Aleena (Curate) on May 04, 2013 at 02:10 UTC

    OOPS! I did not update the example code in the synopsis. It has been updated now.

    For the other issues, here goes.

    1. You are basically asking for the history of how all of this began about six years ago. You might want to read my home node for the history.
    2. Most other HTML modules use OO. I am a function oriented person and wrote this so I could have easier to use (for me) functions.

    Do you know how big my files would be if I statically produced HTML? My site menu alone is 41.2 kb. Keeping it updated across approximately 300 pages would cripple me. When I first started, without being able to produce my site menu with programming, I would have had to quit after only a few pages (since at the time I had a space cap of 10 Mb). Perl has allowed me to keep my file sizes extremely small in some places.

    Another bit of history, some did not like seeing me printing HTML directly in my code, and others loathe my line subroutine. So a few months ago, I decided to see if I could start hiding both. One serendipitous side effect of writing this was I was separating my logic from my display, which many here have been telling me to do all along, I just had not seen how to do it. (One script I wrote was three screens long, with this module I was able to reduce it to less than one.)

    I can not speak for the other authors, so I will only speak of my own work with head and body.

    • The head of an HTML document is not printed to the screen, so the order of the elements inside it do not have to be in any particular order, so I came up with an arbitrary order for them to appear and was able to have their values assigned in a hashref.
    • The body of an HTML document is printed to the screen, so the order of the elements inside it does matter, so I could not make any arbitrary order for them to appear meaning I have to use coderefs so the elements appear on the order I (or the user) wish them to appear. body and other structural elements can have almost anything inside them. An aside could contain a ramble which includes several paragraphs and a table. A section could include several paragraphs with a list between the third and fourth paragraphs.

    Here is the template I wrote for my pages using the module...

    sub my_html_template { my (%opt) = @_; my $heading = textify(basename($0)) !~ /index/ ? textify(basename($0 +)) : 'My '.lc((split(/\//,cwd))[-1]); my $title = textify(join(' - ',($root_name,map(ucfirst,split(/\//,$r +elative_path))))); $title .= textify(" - $opt{heading}") if $opt{heading}; my $page_heading = $opt{heading} ? $opt{heading} : $heading; my $page_heading_id = idify($page_heading); $page_heading =~ s/_/ /g; html(0, { head => { title => $title, links => [map {{ rel => 'stylesheet', type => 'text/css', href = +> $_ }} get_styles($root_path.'/files/css')], scripts => [{ type => 'text/javascript', src => "$root_link/file +s/javascript/list.js" }] }, body => [ sub { nav(2, sub { heading(3,1,'Site menu', { id => 'Site_menu' }); list(4,'u',get_menu( directory => $root_path, tab => 2, color +=> 0, full => 0 ), { onclick => 'list_onclick(event)' }); link_list(3,qq($root_user off-site),%other_sites); link_list(3,qq(Reciprocated links),%reciprocated_links); }); article(2, sub { heading(3,1,$page_heading, { id => $page_heading_id }); &{$opt{code}}; paragraph(4,"Contact $link{mail}!", { class => 'address' }); # + I should use the address tag here. paragraph(4,'I am against the Internet Blacklist Legislation . +..', { class => 'address' }); }); }], }); }

    I went one step further for a lot of my pages with this...

    sub story { my ($source) = @_; my $tab = 3; while (my $line = <$source>) { chomp($line); if ($line =~ m/^</) { line($tab,$line); } elsif ($line =~ /^[1-6]\s/) { my ($heading,$text) = split(/ /,$line,2); heading($tab,$heading,$text); } elsif ($line =~ /^[bh]r$/) { line($tab,"<$line>"); } else { paragraph($tab,$line); } } }

    So, when I go to display the page, I can do this...

    my_html_template( code => sub { story(*DATA) });

    Did that cover everything?

    Have a cookie and a very nice day!
    Lady Aleena

      Possibly not the answer you are looking for, but I hope not. I was thinkng on your code and how to bring the program into the functional by means of introducing some kind of presumptive end_tag method. On reflection I realised that this was already in place in the module. Foiled again!

      Now, you mention that you have not fared well with objects so far, and CGI is not an easy beast to tame. At first I also did not comprehend the difference between the functional and the objective approach. Both importing functions and using the object syntax, but I got the script working. With the help of ardous study, and some lenient monks :) is both though and the difference in use is derived from how you harness the functions in your script. Either by calling them as functions, thus requiring the need to provide an import list, or in the object method calling way which does not need an import list. A trivial understanding of importing helps here. see documentation.

      I also think it important to realise that there are many issues in your script that have already been addressed and refined in, for example security, and differing server architectures (eol phrasing). And by using you can gain knowledge of objects, while being productive with functions.

      Here is the example from before, but in CGI functional format. This shows that CGI can be relatively painless. And you can introduce more complex structures as you become familiar with the way of the CGI. In particular the import of a tag preceded by the asterisk chr '*' is probably the key to where i have been attempting to lead you in my previous responses.

      #!/usr/bin/perl -T use strict; use warnings;# qw(fatalsToBrowser warningsToBrowser); # FATAL => qw( a +ll ); #use Base::HTML::Element; #CGI's functional interface, importing a standard set of subroutines #and the specified qw( *tag ) start_tag end_tag switch/pragma/syntax. #read the pod for descriptons of these use CGI qw(:standard *div); #sends HTML to server for humans to read, #comment out to collapse whitespace use CGI::Pretty; print header; #defaults to xml but can be defined to an HTML namespace print start_html( -title=>'My page title', -style=>{'src'=>'css/style.css'}, -script=>{'type'=>'JAVASCRIPT', 'src'=>'javascript/script.js'}, ); # end start_html, auto prints body opentag. print start_div({-class => 'div_class' }); #note start_div - else clos +es print h1({-id => 'sample_heading', -style => 'color:#666' },'My sample + heading 1'); print p('A sample paragraph so you can see how this works.'); #css styling to do print ul({-id=>'colors'}, li({-type=>'disc',-style => 'color:#f00' },'red'), li({-type=>'disc',-style => 'color:#0f0' },'green'), li({-type=>'disc',-style => 'color:#00f' },'blue'), ); print p('Another paragraph for you'); print h2('A second sample heading'); print p('Guacamole or Bust'); print end_div(); # from imported *div flag print p({ id => 'end_remarks', class => 'remarks' }, 'Some end remarks +.'); print end_html();

      Of course learning coding through constructing your own versions is a great way to learn, I too do this. The really hard thing is trying to find something that has not already been done, or at least something you (or I, tbh) may really have a shot at improving on.

      I don't really see CGI going away anytime soon. CGI caters for unknown tags and such. And I'm pretty sure there have been a few changes since last time I viewed it, if only my understanding. But I do start to see possible patch opportunities here and there... well on some modules, mostly doublestuff or refchecking.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-06-26 18:39 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (586 votes). Check out past polls.