package Saltine::Toffee; my $oven = Oven->new(); $oven->preheat( Fahrenheit => 400 ); my $pan = Saucepan->new(); $pan->heat( "medium" ); $pan += Ingredient->new( "butter", cup => .5 ); $pan += Ingredient->new( "sugar", cup => .5 ); $pan->melt(); $pan->bubble($_) for Time->new( minute => (1 || 2) ); my $sheet = Cookie::Sheet->new(); $sheet->line( with => "foil" ); $sheet->spread( Ingredient->new( "crackers", type => "saltine" ), layer => "single" ); $sheet->pour( $pan->contents(), over => "crackers" ); $oven->bake( $sheet, $_ ) for Time->new( minute => 5, or => "bubbly" ) +; $oven->remove( $sheet ); Immediately: $sheet->sprinkle( Ingredient->new( "chips", type => "chocolate", cup = +> 1 ), over => "crackers" ); wait() until $sheet->contents( "chips" )->state( "melted" ); $sheet->refrigerate() until $sheet->contents()->state( "cool" ); my $toffee = $sheet->contents(); my @enjoy = split /pieces/, $toffee;
If you don't think this is poetry, try some and reconsider.

Replies are listed 'Best First'.
Re: Saltine::Toffee
by robot_tourist (Hermit) on Dec 28, 2005 at 13:03 UTC

    But do you have to get a new oven and pan every time?

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

      But do you have to get a new oven and pan every time?

      I think that this:

      $pan->melt­();

      explains the need for a "new pan every time". And I doubt doing that leaves the oven in very good shape either.

      - tye        

        yes yes, (and lol! tye), i was just thinking about that.

        i think the "correct" $pan handling block ought to be:
        my $pan = Saucepan->new(); $pan->heat( "medium" ); wait() until $pan->temperature( "warm" ); $pan += Ingredient->new( "butter", cup => .5 ); $pan += Ingredient->new( "sugar", cup => .5 ); wait() until $pan->contents()->state( "melted" ); $pan->bubble($_) for Time->new( minute => (1 || 2) );
      But do you have to get a new oven and pan every time?

      Of course not. Those new methods just return refs to singleton instances.

      We're building the house of the future together.
        There's a lot going on that's not obvious at first.

        Note that ->contents() can either be passed an ID to return a particular content object from the container, or be passed nothing to return an object representing all contained objects. The Saucepan class has a few convenience methods that automatically generate such an object and do the work on it: $pan->melt is just shorthand for $pan->contents()->melt; same with $pan->bubble.

        The Cookie::Sheet class is more generic and doesn't have such methods, since they could cause confusion. Note the $sheet->contents()->state( "cool" ) call; state iterates over each object contained in the object returned by contents() and verifies that they are all "cool". $sheet->state( "cool" ) just checks that the sheet itself is cool; some of it's contents may still be hot.

        Another nice thing is the Ingredient class; it's constructor can take a quantity or it can return a lazy object whose quantity is undetermined until it's actually used in a quantized context, e.g. $sheet->spread( Ingredient->new( "crackers", type => "saltine" ),

Re: Saltine::Toffee
by Lady_Aleena (Priest) on Oct 14, 2010 at 02:50 UTC

    From what little I have understood about objects, the word new isn't some sort of magic word that has to be used. So, to avoid people running to the store to buy a new Oven, Saucepan, and Cookie::Sheet, why not have the following?

    my $oven = Oven->empty() or die "What did you scorch last?"; my $pan = Saucepan->clean() or die "Wash the pan."; my $sheet = Cookie::Sheet->clean() or die "Wash the cookie sheet.";

    If I ever understand objects, I think I will use clear or fresh instead of new just for fun. In the above, empty and clean are more descriptive of the state of the object in my ever so humble opinion.

    Updated: added dies.

    Have a cookie and a very nice day!
    Lady Aleena
Re: Saltine::Toffee
by Tux (Canon) on Oct 14, 2010 at 06:24 UTC

    And in object-speak, one seldom uses $object += ..., as theat requires complicated overloading.

    my $pan = Saucepan->new (); $pan->heat ("medium"); $pan->add (Ingredient->new ("butter", cup => .5)); $pan->add (Ingredient->new ("sugar", cup => .5)); wait () until $pan->content ()->state ("melted"); $pan->bubble ($_) for Time->new (minute => (1 || 2));

    Enjoy, Have FUN! H.Merijn