# each Database::XXX class decorates the database # arg passed during instantiation, and any methods it # doesnt recognise are passed through to the decorated # database. # All done by making the Database:XXX classes inherit # from our Decorator class. # This code illustrates how this looks to users # of the database classes. my $db = Database->new( database => 'sussex' ); # add colour managment sprocs to database my $colour_db = Database::Colour->new( db => $db ); # Database::Colour knows hues hue (implements Rainbows) $colour_db->generateRainbow(); ... checkFlowerColours( db => $colour_db ); sub checkFlowerColours { my %arg = @_; # in this context, we need to add some # garden compost to the colour enabled database my $garden_db = Database::Garden->new( db => $arg{db} ); # sameColour is from Database::Colour if ( $garden_db->sameColour( $garden_db->getLawnColour(), 'brown' ) { # action is from Database::Garden # but hosePipeBan is from Database('sussex') $garden_db->waterPlants() unless $garden_db->hasHosePipeBan(); } }