The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Quick note for those following this: I merged Movies::LookUp and Movies::Display into Movie, so new link to Movie. After reading everyone above, it looks like I will not get to keep all of my eggs in one basket. The reason I named this module LookUp was to show myself I could look up anything I have stored about the movies I have some (small) interest in. I should have just posted the entire ugly module instead of just the easy parts. I honestly thought I would get to keep my hashes (lines 21-268) in the module with the objects. I really do not know if the objects will work as I wish without the data being processed before the objects are called. If you are wondering what has taken me so long to respond, there were a few detours along the way. First I got distracted by the idea of creating a super-duper data getter. The one subroutine to rule them all. So, I wrote get_data and plunked it into Base::Data. (get_data is very similar to random in RolePlaying::Random.) I then applied it to my top nine subroutines which I cut down to five. Then there was the whole CGI discussion which lead me to switch from CGI to CGI::Minimal by editing 15 scripts. Then there was the advice to have my get_hash and get_array subroutines from Base::Data return refs instead of copies which I did by editing 32 files. (That task took me about an hour to track all those hashes and arrays down and make them refs.) When I saw the CRC (class, responsibility, and collaboration) cards, I realized I had subroutines which returned mixed in with subroutines which printed. So, I moved all the returning subroutines out of Display and put them in LookUp. (I left one returning subroutine in Display, but I have reasons.) I had a couple subroutines in my scripts too, so I moved them to LookUp as well. A few subroutines got renamed. So now I am more organized than I was before. After reading the direct replies, I realized I had to divorce my subroutines from the data. So, I went through and refactored almost all of my subroutines to be independent from the data above them. (There are two which are giving me trouble, but I will go into it in just a bit.) I also saw I showed you such a small picture of what the module is about. So to break some assumptions based on just what I initially posted, I am going to show you the big picture. Now, take a deep breath, close your eyes, and relax before you continue. Please. The breakdown of Movie::LookUp There are five different types of movie things. Movies could be in series and franchises and can have seasons and episodes within them. Here is a quick list of definitions.
Here is a table showing what each has. A question mark before a "no" means it could be added in the future.
There are several helper subroutines in this module. get_crossover returns a string for a single crossover for crossovers. search_link returns a link to a series or individual movies with are tv series for get_crossover and series_text. get_crossover and search_link are also two subroutines I can not divorce from the data. unquote_parts processes episode titles. nav_link is an independent subroutine which returns a link for navigating the Movies_by_series script so is used in Movie::Display. Wrapping up Movie::LookUp are these four subroutines which all up for rename so there will be no confusion with Movie::Display.
Movie::Display has the following subroutines.
In the future I will be adding print_franchise. Take another deep breath, close your eyes again, and relax before you continue if you wish. I can not separate the data into its own module just yet because of get_crossover, series_text, and display_simple_movie. They all require the data to be there. I use start_year and end_year while creating the data for series and franchises. So, if I move the data to its own module, I would have a module loop. Movie::LookUp would use Movie::Data in the three former subroutines, and Movie::Data would use Movie::LookUp to create the data. It will not work! I have tried it before with no success. So either I keep all of this mess together or find a way of looking up the data needed in the former three subroutines in a different way. Movie::Data can use Movie::LookUp but not vice versa, imo. I am going to include the three problem subroutines only instead of pasting 317 lines. You can click the link up top to get to the whole (heavily edited) module. Maybe fresh eyes will see something I missed. I have been refactoring this for days as inspiration hit me. get_crossover
search_link
display_simple_movie fixed (see update)
Fixed code
Hopefully after I get wholly organized, I can start seeing what classes, methods, and attributes I have here. Since classes appear to be on top of methods and attributes, I will need to know what should or should not be classes in this. Then I can dive into methods, then attributes. (It appears that is the order of things in OO.) Thank you all for trying to help me get my mind around objects. Update: display_simple_movie is fixed, though I am not entirely happy about how I had to do it. While series are being added to their movies, each movie in the series will have the total amount of movies in the series. $movie->{'series'} has gone from an array to a hash. No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena
In reply to Re: How do I go from procedural to object oriented programming?
by Lady_Aleena
|
|