=head1 NAME XML::Compile::Cache - Cache compiled XML translators =head1 INHERITANCE XML::Compile::Cache is a XML::Compile::Schema is a XML::Compile =head1 SYNOPSIS my $cache = XML::Compile::Cache->new(...); $cache->declare('READER', $type, @options); $cache->declare(RW => \@types, @options); $cache->declare(WRITER => $type, \@options); $cache->compileAll; $cache->compileAll('RW'); # get the cached code ref for the reader my $reader = $cache->reader($type); use Data::Dumper; print Dumper $reader->($xml); # get the cached code ref for the writer, and use it my $xml = $cache->writer($type)->($doc, $perl); print $xml->toString(1); # use the base-class uncached, the XML::Compile::Schema my $do = $cache->compile(READER => $type, @opts); =head1 DESCRIPTION =head1 METHODS =head2 Constructors XML::Compile::Cache-EB(OPTIONS) =over 4 Option --Defined in --Default allow_undeclared any_attribute 'SKIP_ALL' any_element 'SKIP_ALL' hook XML::Compile::Schema undef hooks XML::Compile::Schema [] ignore_unused_tags XML::Compile::Schema key_rewrite XML::Compile::Schema [] opts_readers [] opts_rw [] opts_writers [] prefixes schema_dirs XML::Compile undef typemap XML::Compile::Schema {} . allow_undeclared => BOOLEAN =over 4 When true, you may call the reader or writer with types which were not registered with L. In that case, the reader or writer may also get options passed for the compiler, as long as they are consistent over each use of the type. =back . any_attribute => CODE|'TAKE_ALL'|'SKIP_ALL'|'ATTEMPT' . any_element => CODE|'TAKE_ALL'|'SKIP_ALL'|'ATTEMPT' =over 4 ATTEMPT will convert all any elements, applying the reader for each element found. =back . hook => ARRAY-WITH-HOOKDATA | HOOK . hooks => ARRAY-OF-HOOK . ignore_unused_tags => BOOLEAN|REGEXP . key_rewrite => HASH|CODE|ARRAY-of-HASH-and-CODE . opts_readers => HASH|ARRAY-of-PAIRS . opts_rw => HASH|ARRAY-of-PAIRS =over 4 Options added to both READERs and WRITERS. Options which are passed with L and C or C will overrule these. =back . opts_writers => HASH|ARRAY-of-PAIRS . prefixes => HASH|ARRAY-of-PAIRS =over 4 Define prefix name to name-space mappings. Passed to L for each reader and writer, but also used to permit L to accept types which use a prefix. Specify an ARRAY of (prefix, name-space) pairs, or a HASH which maps name-spaces to prefixes (HASH order is reversed from ARRAY order!) When you wish to collect the results, like usage counts, of the translation processing, you will need to specify a HASH. prefixes => [ mine => $myns, your => $yourns ] prefixes => { $myns => 'mine', $yourns => 'your' } # the previous is short for: prefixes => { $myns => [ uri => $myns, prefix => 'mine', used => 0 ] , $yourns => [ uri => $yourns, prefix => 'your', ...] } =back . schema_dirs => DIRECTORY|ARRAY-OF-DIRECTORIES . typemap => HASH =back =head2 Accessors $obj-EB(HOOKDATA|HOOK|undef) =over 4 See L =back $obj-EB(HOOK, [HOOK, ...]) =over 4 See L =back $obj-EB(CODE|HASH, CODE|HASH, ...) =over 4 See L =back $obj-EB(DIRECTORIES|FILENAME) XML::Compile::Cache-EB(DIRECTORIES|FILENAME) =over 4 See L =back $obj-EB(XML, OPTIONS) =over 4 See L =back $obj-EB(PAIR) =over 4 See L =back $obj-EB(PAIRS) =over 4 See L =back $obj-EB([BOOLEAN]) =over 4 Whether it is permitted to create readers and writers which are not declared cleanly. =back $obj-EB =over 4 See L =back $obj-EB([PAIRS]) =over 4 Returns the HASH with prefix to name-space translations. You should not modify the returned HASH, but can provide PAIRS of additional prefix to namespace relations. =back =head2 Compilers $obj-EB(('READER'|'WRITER'), TYPE, OPTIONS) =over 4 See L =back $obj-EB(['READER'|'WRITER'|'RW', [NAMESPACE]]) =over 4 Compile all the declared readers and writers (default 'RW'). You may also select to pre-compile only the READERs or only the WRITERs. The selection can be limited further by specifying a namespace. By default, the processors are only compiled when used. This method is especially useful in a daemon process, where preparations can take as much time as they want to... and running should be as fast as possible. =back $obj-EB(NODE|REF-XML-STRING|XML-STRING|FILENAME|FILEHANDLE|KNOWN) =over 4 See L =back $obj-EB(TYPE|NAME, OPTIONS) =over 4 Returns the reader for the TYPE, which may be specified as prefixed NAME (see L). OPTIONS are only permitted if L is true, and the same as the previous call to this method. The reader will be compiled the first time that it is used, and that same CODE reference will be returned each next request for the same type. example: my $schema = XML::Compile::Cache->new(\@xsd, prefixes => [ gml => $GML_NAMESPACE ] ); my $data = $schema->reader('gml:members')->($xml); my $getmem = $schema->reader('gml:members'); my $data = $getmem->($xml); =back $obj-EB