From: Steve H. <sh...@ha...> - 2002-04-20 13:16:17
|
You want the user to customize the YAML Store results in two different ways: 1) You want the user to give you a rearranged view of the object. For example, the user might suppress certain fields and calculate others. Examples: package Name; sub YAML_view { my ($self) = @_; # return scalar for YAML return "$self->{first} $self->{middle} $self->{last}" } package AddressBook; sub YAML_view { my ($self) = @_; # exclude certain items for privacy considerations return { items => [ sort {$_->{name}} grep { $_->{listing} ne 'private' } @{$self->{items}} ] } } 2) You want the user to configure how Store works for nodes. I think this is almost always going to happen at the hash level. For example, if you have an array, the decision to inline it or not probably depends on the context of the hash that encloses it. Also, the most common configuration option will probably be sort keys for hashes. package Employee; sub YAML_hash_configure { return YAML::Load(<<END); - Name: {QuoteAlways: 1} - Salary: {SpecialTransfer: 'http://salary.org'} - Responsibilities: CompressSeries: 0 TabularInline: 1 # inlines all elements of array, tries to line up commas # Manager key is omitted END } If you separate the view mechanism from the configure mechanism, I think you might find a way to back into a YAML-based formatting language. |