Beefy Boxes and Bandwidth Generously Provided by pair Networks
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.

  • franchise: a collection of series and movies on the same topic but not necessarily sharing a cosmology. (Example: Superman franchise)
  • series: a collection of movies sharing a cosmology. (Example: 1978 Superman series)
  • movie: a film, miniseries, or television series. Web series and some video games could also be included. (Examples: Superman (1978) and Smallville)
  • season: a collection of television or web episodes. (Example: the first season of Smallville)
  • episode: a part of a miniseries or television or web series. (Example: the pilot of Smallville)

Here is a table showing what each has. A question mark before a "no" means it could be added in the future.

 franchiseseriesmovieseasonepisodeNotes
filmminiseriestv
title yesyesyesyesyesyesyes 
counts yesyesno yesyesyesno 
counts
types
  • series
  • film
  • miniseries
  • television series
  • season
  • episode
  • film
  • miniseries
  • television series
  • season
  • episode
 
  • episode
  • season
  • episode
  • episode
   
start_year yesyesyesyesyes?nono 
end_year yesyesno no yes?nono 
years_running yesyesno no yes?nono season gets this if at least start year added
run_time yesyesno no yes?nono season gets this if at least start year added
links yesyesyesyesyesno no season and episode could be given a Google link
media ?no?noyesyesyes?no?no season and episode inherit from movie
franchise and series can build from children
genre ?no?noyesyesyesno no franchise and series can build from children
about ?no?noyesyesyesno no franchise and series can build from children
basis ?no?noyesyesyesno no franchise and series can build from children
crossovers no no no yesyesno yes 
series_text no no yesyesyesno no 
mini_parts no no no yesno no no 
programs yesyesno no no no no 

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.

  • display_movie returns a sentence or two about a movie.
  • display_simple_movie returns a movie title and the start year, it is also a subroutine I can not find a way to divorce from the data.
  • display_episode returns the processed episode name with any crossovers.
  • display_option returns processed selection options.

Movie::Display has the following subroutines.

  • print_series
  • print_movie
  • print_season
  • like (It is a returning subroutine, but I just left it here since it is so text heavy.)

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
# returns a string for a single crossover. The input is a hash ref. sub get_crossover { my ($crossover) = @_; my $episode = $crossover->{'episode'}; my $season = $crossover->{'season'}; my $program = $crossover->{'movie'}; my $cseries = $crossover->{'series'}; my $crossover_text = undef; if ($episode || $season || $program || $cseries) { my $season_text = $season ? "season $season" : undef; my $episode_text = $episode ? textify(qq( "$episode")) : ''; my $search = $cseries ? $cseries : $program ? $program : undef; my $id = $cseries && $series->{$cseries} ? [grep(defined,($program +,$season_text))] : $program && $movies->{$program} && $season_text ? +[$season_text] : undef; $crossover_text = search_link($search,$id).qq($episode_text); } return $crossover_text; }
search_link
# creates a link to the Movies_by_series page. It is used in series_te +xt, get_crossover, and elsewhere. sub search_link { my ($movie, $id) = @_; my $search = undef; my $texti = textify($movie); if (($series->{$movie} && $id) || ($movies->{$movie} && $id)) { $search = searchify($movie,$id); $texti = $movies->{$id->[0]} ? textify($id->[0]) : textify($movie +); } elsif($series->{$movie} || $movies->{$movie}) { $search = searchify($movie); } my $text = "<i>$texti</i>"; my $root_link = get_root('link'); my $search_text = $search ? anchor($text, { 'href' => "$root_link/Mo +vies/Movies_by_series.pl?series=$search" }) : $text; return $search_text; }
display_simple_movie fixed (see update)
# returns the title in italics and the start year in parentheses. sub display_simple_movie { my ($imovie) = @_; my $movie = movie($imovie, 'display_simple_movie'); my $title = textify($imovie); my $start = $movie->{'start year'} ? $movie->{'start year'} : undef; my $item; if ($movie->{'series'}) { my $group; if (@{$movie->{'series'}} > 1) { ($group) = sort { scalar @{$series->{$b}{'programs'}} <=> scalar + @{$series->{$a}{'programs'}} } @{$movie->{'series'}}; } else { $group = $movie->{'series'}[0]; } $item = search_link($group, [$movie->{'title'}]); } elsif ($movie->{'seasons'}) { $item = search_link($movie->{'title'}); } else { $item = "<i>$title</i>"; } $item .= $start ? " ($start)" : undef; return $item; }
Fixed code
# returns the title in italics and the start year in parentheses. sub display_simple_movie { my ($movie) = @_; my $title = textify($movie->{'title'}); my $start = $movie->{'start year'} ? $movie->{'start year'} : undef; my $item; if ($movie->{'series'}) { my $group; my @list = keys %{$movie->{'series'}}; if (keys %{$movie->{'series'}} > 1) { ($group) = sort { $movie->{'series'}{$b} <=> $movie->{'series'}{ +$a} } keys %{$movie->{'series'}}; } else { $group = $list[0]; } $item = search_link($group, [$movie->{'title'}]); } elsif ($movie->{'seasons'}) { $item = search_link($movie->{'title'}); } else { $item = "<i>$title</i>"; } $item .= $start ? " ($start)" : undef; return $item; }

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
in thread How do I go from procedural to object oriented programming? by Lady_Aleena

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found