in reply to Re: Saltine::Toffee
in thread Saltine::Toffee

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.

Replies are listed 'Best First'.
Re^3: Saltine::Toffee
by ysth (Canon) on Dec 30, 2005 at 11:24 UTC
    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" ),