XML-Compile-Cache-1.06/0000755000175000001440000000000013247067373015221 5ustar00markovusers00000000000000XML-Compile-Cache-1.06/lib/0000755000175000001440000000000013247067373015767 5ustar00markovusers00000000000000XML-Compile-Cache-1.06/lib/XML/0000755000175000001440000000000013247067373016427 5ustar00markovusers00000000000000XML-Compile-Cache-1.06/lib/XML/Compile/0000755000175000001440000000000013247067373020017 5ustar00markovusers00000000000000XML-Compile-Cache-1.06/lib/XML/Compile/Cache.pm0000644000175000001440000004176413247067372021373 0ustar00markovusers00000000000000# Copyrights 2008-2018 by [Mark Overmeer]. # For other contributors see ChangeLog. # See the manual pages for details on the licensing terms. # Pod stripped from pm file by OODoc 2.02. # This code is part of distribution XML-Compile. Meta-POD processed with # OODoc into POD and HTML manual-pages. See README.md # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. package XML::Compile::Cache; use vars '$VERSION'; $VERSION = '1.06'; use base 'XML::Compile::Schema'; use warnings; use strict; use Log::Report 'xml-compile-cache'; use XML::Compile::Util qw/pack_type unpack_type/; use List::Util qw/first/; use Scalar::Util qw/weaken/; use XML::LibXML::Simple qw/XMLin/; sub init($) { my ($self, $args) = @_; $self->addPrefixes($args->{prefixes}); $self->SUPER::init($args); $self->{XCC_opts} = delete $args->{opts_rw} || []; $self->{XCC_ropts} = delete $args->{opts_readers} || []; $self->{XCC_wopts} = delete $args->{opts_writers} || []; $self->{XCC_undecl} = delete $args->{allow_undeclared} || 0; $self->{XCC_dropts} = {}; # declared opts $self->{XCC_dwopts} = {}; $self->{XCC_uropts} = {}; # undeclared opts $self->{XCC_uwopts} = {}; $self->{XCC_readers} = {}; # compiled code refs; $self->{XCC_writers} = {}; $self->typemap($args->{typemap}); $self->xsiType($args->{xsi_type}); $self->anyElement($args->{any_element} || 'ATTEMPT'); $self; } #---------------------- sub typemap(@) { my $self = shift; my $t = $self->{XCC_typemap} ||= {}; my @d = @_ > 1 ? @_ : !defined $_[0] ? () : ref $_[0] eq 'HASH' ? %{$_[0]} : @{$_[0]}; while(@d) { my $k = $self->findName(shift @d); $t->{$k} = shift @d } $t; } sub addXsiType(@) { my $self = shift; my $x = $self->{XCC_xsi_type} ||= {}; my @d = @_ > 1 ? @_ : !defined $_[0] ? () : ref $_[0] eq 'HASH' ? %{$_[0]} : @{$_[0]}; while(@d) { my $k = $self->findName(shift @d); my $a = shift @d; $a = $self->namespaces->autoexpand_xsi_type($k) || [] if $a eq 'AUTO'; push @{$x->{$k}} , ref $a eq 'ARRAY' ? (map $self->findName($_), @$a) : $self->findName($a); } $x; } *xsiType = \&addXsiType; sub allowUndeclared(;$) { my $self = shift; @_ ? ($self->{XCC_undecl} = shift) : $self->{XCC_undecl}; } sub anyElement($) { my ($self, $anyelem) = @_; # the "$self" in XCC_ropts would create a ref-cycle, causing a # memory leak. my $s = $self; weaken $s; my $code = $anyelem eq 'ATTEMPT' ? sub {$s->_convertAnyTyped(@_)} : $anyelem eq 'SLOPPY' ? sub {$s->_convertAnySloppy(@_)} : $anyelem; $self->addCompileOptions(READERS => any_element => $code); $code; } #---------------------- sub addPrefixes(@) { my $self = shift; my $p = $self->{XCC_namespaces} ||= {}; my $first = shift; @_ or defined $first or return $p; my @pairs = @_ ? ($first, @_) : ref $first eq 'ARRAY' ? @$first : ref $first eq 'HASH' ? %$first : error __x"prefixes() expects list of PAIRS, an ARRAY or a HASH"; my $a = $self->{XCC_prefixes} ||= {}; while(@pairs) { my ($prefix, $ns) = (shift @pairs, shift @pairs); $p->{$ns} ||= { uri => $ns, prefix => $prefix, used => 0 }; if(my $def = $a->{$prefix}) { if($def->{uri} ne $ns) { error __x"prefix `{prefix}' already refers to {uri}, cannot use it for {ns}" , prefix => $prefix, uri => $def->{uri}, ns => $ns; } } else { $a->{$prefix} = $p->{$ns}; trace "register prefix $prefix for '$ns'"; } } $p; } sub prefixes(@) { my $self = shift; return $self->addPrefixes(@_) if @_; $self->{XCC_namespaces} || {}; } sub prefix($) { $_[0]->{XCC_prefixes}{$_[1]} } # [0.995] should this be public? sub byPrefixTable() { shift->{XCC_prefixes} } sub prefixFor($) { my $def = $_[0]->{XCC_namespaces}{$_[1]} or return (); $def->{used}++; $def->{prefix}; } sub addNicePrefix($$) { my ($self, $base, $ns) = @_; if(my $def = $self->prefix($base)) { return $base if $def->{uri} eq $ns; } else { $self->addPrefixes($base => $ns); return $base; } $base .= '01' if $base !~ m/[0-9]$/; while(my $def = $self->prefix($base)) { return $base if $def->{uri} eq $ns; $base++; } $self->addPrefixes($base => $ns); $base; } sub learnPrefixes($) { my ($self, $node) = @_; my $namespaces = $self->prefixes; PREFIX: foreach my $ns ($node->getNamespaces) # learn preferred ns { my ($prefix, $uri) = ($ns->getLocalName, $ns->getData); next if !defined $prefix || $namespaces->{$uri}; if(my $def = $self->prefix($prefix)) { next PREFIX if $def->{uri} eq $uri; } else { $self->addPrefixes($prefix => $uri); next PREFIX; } $prefix =~ s/0?$/0/; while(my $def = $self->prefix($prefix)) { next PREFIX if $def->{uri} eq $uri; $prefix++; } $self->addPrefixes($prefix => $uri); } } sub addSchemas($@) { my ($self, $xml) = (shift, shift); $self->learnPrefixes($xml); $self->SUPER::addSchemas($xml, @_); } sub prefixed($;$) { my $self = shift; my ($ns, $local) = @_==2 ? @_ : unpack_type(shift); $ns or return $local; my $prefix = $self->prefixFor($ns); defined $prefix or error __x"no prefix known for namespace `{ns}', use addPrefixes()" , ns => $ns; length $prefix ? "$prefix:$local" : $local; } #---------------------- sub compileAll(;$$) { my ($self, $need, $usens) = @_; my ($need_r, $need_w) = $self->_need($need || 'RW'); if($need_r) { foreach my $type (keys %{$self->{XCC_dropts}}) { if(defined $usens) { my ($myns, $local) = unpack_type $type; next if $usens eq $myns; } $self->reader($type); } } if($need_w) { foreach my $type (keys %{$self->{XCC_dwopts}}) { if(defined $usens) { my ($myns, $local) = unpack_type $type; next if $usens eq $myns; } $self->writer($type); } } } sub _same_params($$) { my ($f, $s) = @_; @$f==@$s or return 0; for(my $i=0; $i<@$f; $i++) { return 0 if !defined $f->[$i] ? defined $s->[$i] : !defined $s->[$i] ? 1 : $f->[$i] ne $s->[$i]; } 1; } sub reader($@) { my ($self, $name) = (shift, shift); my %args = @_; my $type = $self->findName($name); my $readers = $self->{XCC_readers}; if(exists $self->{XCC_dropts}{$type}) { trace __x"ignoring options to pre-declared reader {name}" , name => $name if @_; return $readers->{$type} if $readers->{$type}; } elsif($self->allowUndeclared) { if(my $ur = $self->{XCC_uropts}{$type}) { # do not use cached version when options differ _same_params $ur, \@_ or return $args{is_type} ? $self->compileType(READER => $type, @_) : $self->compile(READER => $type, @_); } else { $self->{XCC_uropts}{$type} = \@_; } } elsif(exists $self->{XCC_dwopts}{$type}) { error __x"type {name} is only declared as writer", name => $name } else { error __x"type {name} is not declared", name => $name } $readers->{$type} ||= $args{is_type} ? $self->compileType(READER => $type, @_) : $self->compile(READER => $type, @_); } sub writer($%) { my ($self, $name) = (shift, shift); my %args = @_; my $type = $self->findName($name); my $writers = $self->{XCC_writers}; if(exists $self->{XCC_dwopts}{$type}) { trace __x"ignoring options to pre-declared writer {name}" , name => $name if @_; return $writers->{$type} if $writers->{$type}; } elsif($self->{XCC_undecl}) { if(my $ur = $self->{XCC_uwopts}{$type}) { # do not use cached version when options differ _same_params $ur, \@_ or return $args{is_type} ? $self->compileType(WRITER => $type, @_) : $self->compile(WRITER => $type, @_); } else { $self->{XCC_uwopts}{$type} = \@_; } } elsif(exists $self->{XCC_dropts}{$type}) { error __x"type {name} is only declared as reader", name => $name; } else { error __x"type {name} is not declared", name => $name; } $writers->{$type} ||= $args{is_type} ? $self->compileType(WRITER => $type, @_) : $self->compile(WRITER => $type, @_); } sub template($$@) { my ($self, $action, $name) = (shift, shift, shift); $action =~ m/^[A-Z]*$/ or error __x"missing or illegal action parameter to template()"; my $type = $self->findName($name); my @opts = $self->mergeCompileOptions($action, $type, \@_); $self->SUPER::template($action, $type, @opts); } sub addCompileOptions(@) { my $self = shift; my $need = @_%2 ? shift : 'RW'; my $set = $need eq 'RW' ? $self->{XCC_opts} : $need eq 'READERS' ? $self->{XCC_ropts} : $need eq 'WRITERS' ? $self->{XCC_wopts} : error __x"addCompileOptions() requires option set name, not {got}" , got => $need; if(ref $set eq 'HASH') { while(@_) { my $k = shift; $set->{$k} = shift } } else { push @$set, @_ } $set; } # Create a list with options for X::C::Schema::compile(), from a list of ARRAYs # and HASHES with options. The later options overrule the older, but in some # cases, the new values are added. This method knows how some of the options # of ::compile() behave. [last update X::C v0.98] sub mergeCompileOptions($$$) { my ($self, $action, $type, $opts) = @_; my @action_opts = ($action eq 'READER' || $action eq 'PERL') ? ($self->{XCC_ropts}, $self->{XCC_dropts}{$type}) : ($self->{XCC_wopts}, $self->{XCC_dwopts}{$type}); my %p = %{$self->{XCC_namespaces}}; my %t = %{$self->{XCC_typemap}}; my %x = %{$self->{XCC_xsi_type}}; my %opts = (prefixes => \%p, hooks => [], typemap => \%t, xsi_type => \%x); # flatten list of parameters my @take = map {!defined $_ ? () : ref $_ eq 'ARRAY' ? @$_ : %$_ } $self->{XCC_opts}, @action_opts, $opts; while(@take) { my ($opt, $val) = (shift @take, shift @take); defined $val or next; if($opt eq 'prefixes') { my $t = $self->_namespaceTable($val, 1, 0); # expand @p{keys %$t} = values %$t; # overwrite old def if exists } elsif($opt eq 'hooks' || $opt eq 'hook') { my $hooks = $self->_cleanup_hooks($val); unshift @{$opts{hooks}}, ref $hooks eq 'ARRAY' ? @$hooks : $hooks if $hooks; } elsif($opt eq 'typemap') { $val ||= {}; if(ref $val eq 'ARRAY') { while(@$val) { my $k = $self->findName(shift @$val); $t{$k} = shift @$val; } } else { while(my($k, $v) = each %$val) { $t{$self->findName($k)} = $v; } } } elsif($opt eq 'key_rewrite') { unshift @{$opts{key_rewrite}}, ref $val eq 'ARRAY' ? @$val : $val; } elsif($opt eq 'xsi_type') { while(my ($t, $a) = each %$val) { my @a = ref $a eq 'ARRAY' ? map($self->findName($_), @$a) : $self->findName($a); push @{$x{$self->findName($t)}}, @a; } } elsif($opt eq 'ignore_unused_tags') { $opts{$opt} = defined $opts{$opt} ? qr/$opts{$opt}|$val/ : $val; } else { $opts{$opt} = $val; } } %opts; } # rewrite hooks sub _cleanup_hooks($) { my ($self, $hooks) = @_; $hooks or return; # translate prefixed type names into full names foreach my $hook (ref $hooks eq 'ARRAY' ? @$hooks : $hooks) { if(my $types = $hook->{type}) { $hook->{type} = [ map {ref $_ eq 'Regexp' ? $_ : $self->findName($_)} ref $types eq 'ARRAY' ? @$types : $types ]; } elsif(my $ext = $hook->{extends}) { $hook->{extends} = $self->findName($ext); } } $hooks; } my %need = (READER => [1,0], WRITER => [0,1], RW => [1,1]); $need{READERS} = $need{READER}; $need{WRITERS} = $need{WRITER}; sub _need($) { my $need = $need{$_[1]} or error __x"use READER, WRITER or RW, not {dir}", dir => $_[1]; @$need; } # support prefixes on types sub addHook(@) { my $self = shift; my $hook = @_ > 1 ? {@_} : shift; $self->_cleanup_hooks($hook); $self->SUPER::addHook($hook); } sub compile($$@) { my ($self, $action, $elem) = splice @_, 0, 3; defined $elem or error __x"compile() requires action and type parameters"; $self->SUPER::compile ( $action => $self->findName($elem) , $self->mergeCompileOptions($action, $elem, \@_) ); } sub compileType($$@) { my ($self, $action, $type) = splice @_, 0, 3; defined $type or error __x"compileType() requires action and type parameters"; $self->SUPER::compileType ( $action => $self->findName($type) , $self->mergeCompileOptions($action, $type, \@_) ); } #---------------------- sub declare($$@) { my ($self, $need, $names, @opts) = @_; my $opts = @opts==1 ? shift @opts : \@opts; $opts = [ %$opts ] if ref $opts eq 'HASH'; my ($need_r, $need_w) = $self->_need($need); foreach my $name (ref $names eq 'ARRAY' ? @$names : $names) { my $type = $self->findName($name); trace "declare $type $need"; if($need_r) { defined $self->{XCC_dropts}{$type} and warning __x"reader {name} declared again", name => $name; $self->{XCC_dropts}{$type} = $opts; } if($need_w) { defined $self->{XCC_dwopts}{$type} and warning __x"writer {name} declared again", name => $name; $self->{XCC_dwopts}{$type} = $opts; } } $self; } sub findName($) { my ($self, $name) = @_; defined $name or panic "findName called without name"; return $name if substr($name, 0, 1) eq '{'; my ($prefix,$local) = $name =~ m/^([\w-]*)\:(\S*)$/ ? ($1,$2) : ('',$name); my $def = $self->{XCC_prefixes}{$prefix}; unless($def) { return $name if $prefix eq ''; # namespace-less trace __x"known prefixes: {prefixes}" , prefixes => [ sort keys %{$self->{XCC_prefixes}} ]; error __x"unknown name prefix `{prefix}' for `{name}'" , prefix => $prefix, name => $name; } length $local ? pack_type($def->{uri}, $local) : $def->{uri}; } sub printIndex(@) { my $self = shift; my $fh = @_ % 2 ? shift : select; my %args = @_; my $decl = exists $args{show_declared} ? delete $args{show_declared} : 1; return $self->SUPER::printIndex($fh, %args) unless $decl; my $output = ''; open my($out), '>', \$output; $self->SUPER::printIndex($out, %args); close $out; my @output = split /(?<=\n)/, $output; my $ns = ''; foreach (@output) { $ns = $1 if m/^namespace\:\s+(\S+)/; my $local = m/^\s+(\S+)\s*$/ ? $1 : next; my $type = pack_type $ns, $local; substr($_, 1, 1) = $self->{XCC_readers}{$type} ? 'R' : $self->{XCC_dropts}{$type} ? 'r' : ' '; substr($_, 2, 1) = $self->{XCC_writers}{$type} ? 'W' : $self->{XCC_dwopts}{$type} ? 'w' : ' '; } $fh->print(@output); } #--------------- # Convert ANY elements and attributes sub _convertAnyTyped(@) { my ($self, $type, $nodes, $path, $read) = @_; my $key = $read->keyRewrite($type); if(defined(my $blocked = $read->blocked($path, complexType => $type))) { trace "skipping blocked $type"; return (); } my $reader = try { $self->reader($type) }; if($@) { trace "cannot auto-convert 'any': ".$@->wasFatal->message; return ($key => $nodes); } trace "auto-convert known type for 'any': $type"; my @nodes = ref $nodes eq 'ARRAY' ? @$nodes : $nodes; my @convert = map $reader->($_), @nodes; ($key => (@convert==1 ? $convert[0] : \@convert) ); } sub _convertAnySloppy(@) { my ($self, $type, $nodes, $path, $read) = @_; my $key = $read->keyRewrite($type); my $reader = try { $self->reader($type) }; if($@) { # unknown type or untyped... my @convert = map XMLin($_), @$nodes; return ($key => @convert==1 ? $convert[0] : \@convert); } else { trace "auto-convert known 'any' $type"; my @nodes = ref $nodes eq 'ARRAY' ? @$nodes : $nodes; my @convert = map $reader->($_), @nodes; ($key => @convert==1 ? $convert[0] : \@convert); } } 1; XML-Compile-Cache-1.06/lib/XML/Compile/Cache.pod0000644000175000001440000004327513247067372021540 0ustar00markovusers00000000000000=encoding utf8 =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, @opts); use Data::Dumper; print Dumper $reader->($xml); # get the cached code ref for the writer, and use it my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); 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 Extends L<"DESCRIPTION" in XML::Compile::Schema|XML::Compile::Schema/"DESCRIPTION">. =head1 METHODS Extends L<"METHODS" in XML::Compile::Schema|XML::Compile::Schema/"METHODS">. =head2 Constructors Extends L<"Constructors" in XML::Compile::Schema|XML::Compile::Schema/"Constructors">. =over 4 =item XML::Compile::Cache-EB( [$xml], %options ) -Option --Defined in --Default allow_undeclared any_element 'ATTEMPT' block_namespace XML::Compile::Schema [] 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 [] parser_options XML::Compile prefixes schema_dirs XML::Compile undef typemap {} xsi_type {} =over 2 =item allow_undeclared => BOOLEAN 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. =item any_element => CODE|'TAKE_ALL'|'SKIP_ALL'|'ATTEMPT'|'SLOPPY' See L. [1.02] the default is to ATTEMPT compiling any handlers automatically. Before version 1.02, the default was to SKIP_ALL elements which would match the occurs and namespace restrictions of the any specification. However, that fails for reperative blocks (for instance, it fails for an choice which may occur unbounded times) =item block_namespace => NAMESPACE|TYPE|HASH|CODE|ARRAY =item hook => $hook|ARRAY =item hooks => ARRAY =item ignore_unused_tags => BOOLEAN|REGEXP =item key_rewrite => HASH|CODE|ARRAY =item opts_readers => HASH|ARRAY-of-PAIRS =item opts_rw => HASH|ARRAY-of-PAIRS Options added to both READERs and WRITERS. Options which are passed with L and C or C will overrule these. See L. =item opts_writers => HASH|ARRAY-of-PAIRS =item parser_options => HASH|ARRAY =item prefixes => HASH|ARRAY-of-PAIRS 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', ...] } =item schema_dirs => $directory|ARRAY-OF-directories =item typemap => HASH|ARRAY =item xsi_type => HASH|ARRAY =back =back =head2 Accessors Extends L<"Accessors" in XML::Compile::Schema|XML::Compile::Schema/"Accessors">. =over 4 =item $obj-EB($hook|LIST|undef) Inherited, see L =item $obj-EB( $hook, [$hook, ...] ) Inherited, see L =item $obj-EB($predef|CODE|HASH, ...) Inherited, see L =item $obj-EB(@directories|$filename) =item XML::Compile::Cache-EB(@directories|$filename) Inherited, see L =item $obj-EB($xml, %options) Inherited, see L =item $obj-EB(PAIR) Inherited, see L =item $obj-EB(PAIRS) Inherited, see L =item $obj-EB( [HASH|ARRAY|LIST] ) [1.01] add global xsi_type declarations. Returns the xsiType set. The ARRAY or LIST contains pairs, just like the HASH. The value component can be 'AUTO' to automatically detect the C extensions. This does only work for complex types. =item $obj-EB( [BOOLEAN] ) Whether it is permitted to create readers and writers which are not declared cleanly. =item $obj-EB('ATTEMPT'|'SLOPPY'|'SKIP_ALL'|'TAKE_ALL'|CODE) [as method since 0.99] How to process ANY elements, see also L. Reader: C will convert all any elements, applying the reader for each element found. When an element is not found in a schema, it will be included as XML::LibXML::Element node. [0.93] Reader: With C, first automatic typed conversion is attempted. But is the type is not known, L is called to the resque. =item $obj-EB($ns|$type|HASH|CODE|ARRAY) Inherited, see L =item $obj-EB( [<'READER'|'WRITER'>] ) Inherited, see L =item $obj-EB( [HASH|ARRAY|PAIRS] ) [0.98] Add global knowledge on typemaps. Returns the typemap. =item $obj-EB( $schema, [$schema, ...] ) Inherited, see L =back =head2 Prefix management The cache layer on top of L adds smart use of prefixes. Of course, smartness comes with a small performance cost, but the code gets much cleaner. =over 4 =item $obj-EB(BASE, NAMESPACE) [1.03] Register NAMESPACE -if not yet defined- with prefix name BASE. When that prefix name is already in use for some other namespace, BASE followed by a number are attempted (starting with 01). The prefix is returned. When the BASE already ends on a number, that number will get counted. example: my $prefix = $schema->addNicePrefix('call', $myns); # $prefix now can be call, call01, call02 etc =item $obj-EB( [PAIRS|ARRAY|HASH] ) The X::C logic does auto-detect prefix/namespaces combinations from the XML, but does not search extensively for namespace declarations. Also, sometimes the same namespace is used with different prefixes. Sometimes, the same prefix is used for different namesapces. To complete the list, or control the actual prefix being used, you explicitly declare combinations. The B to add prefixes is via L, which will give your names preference over the names found in the schema's which get loaded. For instance, use C<< ::WSDL->new(prefixes => [ $prefix => $ns ] >> [0.995] Returns the HASH with prefix to name-space translations. You should not modify the returned HASH: new PAIRS of prefix to namespace relations can be passed as arguments. [0.14] If a name-space appears for the second time, then the new prefix will be recognized by L, but not used in the output. When the prefix already exists for a different namespace, then an error will be casted. [0.90] You may also provide an ARRAY of pairs or a HASH. =item $obj-EB($node) [0.993] Take all the prefixes defined in the $node, and XML::LibXML::Element. This is not recursive: only on those defined at the top $node. =item $obj-EB($prefix) Lookup a prefix definition. This returns a HASH with namespace info. =item $obj-EB($uri) Lookup the preferred prefix for the $uri. =item $obj-EB( $type|<$ns,$local> ) Translate the fully qualified $type into a prefixed version. Will produce undef if the namespace is unknown. [0.993] When your $type is not in packed form, you can specify a namespace and $local type name as separate arguments. example: print $schema->prefixed($type) || $type; print $schema->prefixed($ns, $local); =item $obj-EB( [$params] ) Return prefixes table. The $params are deprecated since [0.995], see L. =back =head2 Compilers The name of this module refers to its power to administer compiled XML encoders (writers) and decoders (readers). This means that your program only need to pass on a ::Cache object (for instance a XML::Compile::WSDL11, not a CODE reference for each compiled translator. Extends L<"Compilers" in XML::Compile::Schema|XML::Compile::Schema/"Compilers">. =over 4 =item $obj-EB( ['READERS'|'WRITERS'|'RW'], %options ) [0.99] You may provide global compile options with L, C and C, but also later using this method. =item $obj-EB( <'READER'|'WRITER'>, $type, %options ) Inherited, see L =item $obj-EB( ['READERS'|'WRITERS'|'RW', [$ns]] ) Compile all the declared readers and writers with the 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 $ns. By default, the processors are only compiled when used. This method is especially useful in a B, where preparations can take as much time as they want to... and running should be as fast as possible. =item $obj-EB( <'READER'|'WRITER'>, $type, %options ) Inherited, see L =item $obj-EB($node|REF-XML|XML-STRING|$filename|$fh|$known) =item XML::Compile::Cache-EB($node|REF-XML|XML-STRING|$filename|$fh|$known) Inherited, see L =item $obj-EB(%options) =item XML::Compile::Cache-EB(%options) Inherited, see L =item $obj-EB($type|$name, %options) Returns the reader CODE for the $type or $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. Call L to have all readers compiled by force. -Option --Default is_type =over 2 =item is_type => BOOLEAN [1.03] use L with the given element, to replace L You probably want an additional C parameter. =back 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); =item $obj-EB