OPC
view release on metacpan or search on metacpan
my $Filter;
if( $RelationParams{type} ) {
$Filter = '@Type="'.$RelationParams{type}.'"';
}
if( $RelationParams{id} ) {
$Filter = '@Id="'.$RelationParams{id}.'"';
}
return $XC->findnodes(
"/opcr:Relationships/opcr:Relationship[$Filter]",
$RelsDoc );
}
# Retrieve relations by type and return list of hashref
sub RelationsByType {
my( $self, $RelsPartName, $RelType ) = @_;
return $self->Relations( $RelsPartName, type => $RelType );
}
# ÐÐ·Ð²Ð»ÐµÐºÐ°ÐµÑ ÑвÑÐ·Ñ Ð·Ð°Ð´Ð°Ð½Ð½Ð¾Ð³Ð¾ Ñипа из rels ÑаÑÑи, ÑÑо ÑвÑÐ·Ñ Ð´Ð°Ð½Ð½Ð¾Ð³Ð¾ Ñипа ÑолÑко одна,
# инаÑе вÑбÑаÑÑÐ²Ð°ÐµÑ ÑаÑалÑнÑÑ Ð¾ÑибкÑ
# Don't use RelationByType with $GetMulty param, use RelationsByType method instead
sub RelationByType {
my( $self, $RelsPartName, $RelType, $GetMulty ) = @_;
my @Relations = $self->RelationsByType( $RelsPartName, $RelType );
if( !$GetMulty && @Relations > 1 ) {
die "Expected only one relation of type $RelType in $RelsPartName but found several";
}
if ($GetMulty) {
return @Relations;
} elsif (@Relations) {
return %{$Relations[0]};
} else {
return ();
}
}
# вÑпомогаÑелÑÐ½Ð°Ñ ÑÑнкÑиÑ: полÑÑиÑÑ Ð¿Ð¾Ð»Ð½Ð¾Ðµ Ð¸Ð¼Ñ ÑаÑÑи по оÑноÑиÑелÑной ÑÑÑлке на неÑ
# и имени ÑаÑÑи, оÑноÑиÑелÑно коÑоÑой иÑем
sub FullPartNameFromRelative {
my $Name = shift;
my $Dir = shift;
$Dir =~ s:/$::; # remove trailing slash
my $FullName = ( $Name =~ m:^/: ) ? $Name : # в $Name - полнÑй пÑÑÑ
"$Dir/$Name"; # в $Name - оÑноÑиÑелÑÐ½Ð°Ñ ÑÑÑлка
$FullName =~ s:^/::; # remove leading slash
$FullName = do{
use bytes; # A-Za-z are case insensitive
lc $FullName;
};
# обÑабаÑÑваем вÑе . и .. в имени
my @CleanedSegments;
my @OriginalSegments = split m:/:, $FullName;
for my $Part ( @OriginalSegments ) {
if( $Part eq '.' ) {
# пÑоÑÑо пÑопÑÑкаем
} elsif( $Part eq '..' ) {
if( @CleanedSegments > 0 ) {
pop @CleanedSegments;
} else {
die "/$FullName part name is invalid, because it's pointing out of FB3 root";
}
} else {
push @CleanedSegments, $Part;
}
}
return '/'.( join '/', @CleanedSegments );
}
sub Root {
my $self = shift;
return OPC::Root->new( package => $self );
}
sub Part {
my( $self, %Params ) = @_;
my $PartName = $Params{name};
return OPC::Part->new( package => $self, name => $PartName )
}
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2018 Litres.ru
The GNU Lesser General Public License version 3.0
OPC is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3.0 of the License.
OPC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
Full text of License L<http://www.gnu.org/licenses/lgpl-3.0.en.html>.
=cut
1;
( run in 1.279 second using v1.01-cache-2.11-cpan-71847e10f99 )