Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I've voluteered to write a small script for a web community.

The details are pretty meaningless, but it's a small SQL database containing Quotes of the Day kind of thing.

All that's needed is to connect to an SQL DB, and edit, save, add and delete quotes via a web front end.

It would normally take me a couple of hours to fix the whole thing up, but the person I'm writing it for likes the code to be object-oriented.

I don't need details of exactly the code I'd use, but I have to admit I still don't really get the OO philosophy.

Here's what I'd probably do for a script like that:

  • create a script
  • feed it a "mode" via the form/query string every time like "if($mode eq 'edit'){ open the db, get record x, populate the fields }" or "if($mode eq 'save'){ open the db, put the field contents into record x}" and so on, the default mode being "none of the above" or start-up mode.
  • create the right forms and HTML code for each "mode".

What's the OO way to approach a simple task like that? I need to make everything into a function, essentially, and then call the functions as methods of the objects? So what are my objects?

As you can see, I've got a mental block about this -- I really see the whole thing as procedures, so I'm hoping my fellow monks can help me translate that into Objects with Methods.
--

($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

In reply to Object-Orienting A Procedural Script by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (8)
    As of 2014-11-22 15:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (123 votes), past polls