| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # $Id: Navigation.pm,v 1.20 2004/03/25 11:56:24 eserte Exp $ | ||||||||||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Copyright (C) 2002 Online Office Berlin. All rights reserved. | ||||||||||||||||||||||||||||
| 8 | # Copyright (C) 2002 Slaven Rezic. | ||||||||||||||||||||||||||||
| 9 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||
| 10 | # terms of the GNU General Public License, see the file COPYING. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||
| 14 | # WWW: http://we-framework.sourceforge.net | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | package WE_Frontend::Plugin::Navigation; | ||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use base qw(Template::Plugin); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | require WE_Frontend::Plugin::Navigation::Object; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 NAME | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | WE_Frontend::Plugin::Navigation - utilities for navigation creation | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"}); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | [% USE Navigation %] | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | C<WE_Frontend::Plugin::Navigation> is a C<Template-Toolkit> plugin to | ||||||||||||||||||||||||||||
| 39 | make the creation of navigations based on objects in a C<WE::DB::Obj> | ||||||||||||||||||||||||||||
| 40 | database easier. The C<WE_Frontend::Plugin::Navigation> object | ||||||||||||||||||||||||||||
| 41 | corresponds somewhat to the C<WE::DB::Obj> database. Most of the | ||||||||||||||||||||||||||||
| 42 | methods described below return | ||||||||||||||||||||||||||||
| 43 | L<WE_Frontend::Plugin::Navigation::Object> objects, which correspond | ||||||||||||||||||||||||||||
| 44 | to L<WE::Obj> objects. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 METHODS | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =over | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item new | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | This method is normally not called directly, but only as part of the | ||||||||||||||||||||||||||||
| 53 | C<USE> directive: | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | [% USE Navigation %] | ||||||||||||||||||||||||||||
| 56 | [% USE n = Navigation %] | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | You can pass the named parameter C<objid> to set the object id for | ||||||||||||||||||||||||||||
| 59 | this context. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | [% USE n = Navigation(objid = 10) %] | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Or you can use the C<name> parameter: | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | [% USE n = Navigation(name = "rootcollection") %] | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | You can pass the named parameter C<objid> to set the object id for | ||||||||||||||||||||||||||||
| 68 | this context. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | When calling the process() method of C<Template-Toolkit> the value for | ||||||||||||||||||||||||||||
| 71 | C<objdb> (a reference to the L<WE::DB::Obj> database) should be set or | ||||||||||||||||||||||||||||
| 72 | C<rootdb> (a reference to the L<WE::DB> database) XXX rootdb prefered if content access. | ||||||||||||||||||||||||||||
| 73 | Also, if C<objid> is not set in the C<USE> directive, it may be | ||||||||||||||||||||||||||||
| 74 | supplied to the process() method. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $t = Template->new( | ||||||||||||||||||||||||||||
| 77 | {PLUGIN_BASE => "WE_Frontend::Plugin"} | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | $t->process( | ||||||||||||||||||||||||||||
| 80 | \$template, | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | objdb => $objdb, | ||||||||||||||||||||||||||||
| 83 | rootdb => $rootdb, | ||||||||||||||||||||||||||||
| 84 | objid => $objid, | ||||||||||||||||||||||||||||
| 85 | config => $c, | ||||||||||||||||||||||||||||
| 86 | langstring => \&WE::Util::LangString::langstring | ||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | \$output | ||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | The return value of the C<USE Navigation> directive (the C<n> variable | ||||||||||||||||||||||||||||
| 92 | in the examples above) is a L<WE_Frontend::Plugin::Navigation::Object> | ||||||||||||||||||||||||||||
| 93 | of the current object supplied with the C<objid> key. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my($class, $context, $params) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | $params ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $rootdb = $params->{rootdb} || eval { $context->stash->get("rootdb") }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$params->{'rootdb'} || eval {
do {
$context->stash->get('rootdb')
}
}
MC/DC0%0/2
$params->{'rootdb'} || eval {
do {
$context->stash->get('rootdb')
}
}
$params->{'rootdb'}
eval {
do {
$context->stash->get('rootdb')
}
}
Truth table0%0/3
A || B
A= $params->{'rootdb'}B= eval {
do {
$context->stash->get('rootdb')
}
}
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $objdb = $params->{objdb} || eval { $context->stash->get("objdb") }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$params->{'objdb'} || eval {
do {
$context->stash->get('objdb')
}
}
MC/DC0%0/2
$params->{'objdb'} || eval {
do {
$context->stash->get('objdb')
}
}
$params->{'objdb'}
eval {
do {
$context->stash->get('objdb')
}
}
Truth table0%0/3
A || B
A= $params->{'objdb'}B= eval {
do {
$context->stash->get('objdb')
}
}
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (!$objdb && $rootdb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $objdb and $rootdb
MC/DC0%0/2
not $objdb and $rootdb
not $objdb
$rootdb
Truth table0%0/3
not(A) and B
A= not $objdbB= $rootdb
| |||||||||||||||||||||||||||||
| 103 | 0 | $objdb = $rootdb->ObjDB; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if (!$objdb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($rootdb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | return $class->error("The required parameter rootdb is defined, but its member ObjDB is not defined"); | |||||||||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||||||||||
| 109 | 0 | return $class->error("The required parameter objdb and/or rootdb is not defined"); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 0 | my $objid = $params->{objid}; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (!defined $objid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (defined $params->{name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | $objid = $objdb->name_to_objid($params->{name}); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (!defined $objid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $objid = eval { $context->stash->get("objid") }; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | my $self = { | |||||||||||||||||||||||||||
| 122 | Context => $context, | ||||||||||||||||||||||||||||
| 123 | RootDB => $rootdb, | ||||||||||||||||||||||||||||
| 124 | ObjDB => $objdb, | ||||||||||||||||||||||||||||
| 125 | ObjID => $objid, | ||||||||||||||||||||||||||||
| 126 | POCache => {}, # for pathobjects_with_cache | ||||||||||||||||||||||||||||
| 127 | }; | ||||||||||||||||||||||||||||
| 128 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =item ancestors([[objid = id | name = name], fromlevel => level, tolevel => level, restrict = restrictmethod]) | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Return a list of ancestors of the current object. The oldest | ||||||||||||||||||||||||||||
| 134 | (top-most) ancestor is first in the list. If C<objid> is given, then | ||||||||||||||||||||||||||||
| 135 | return the ancestors for the object with this object identifier. If | ||||||||||||||||||||||||||||
| 136 | C<fromlevel> and/or C<tolevel> are given, then restrict the ancestor | ||||||||||||||||||||||||||||
| 137 | list for these levels. The topmost level is numbered with 1. The root | ||||||||||||||||||||||||||||
| 138 | itself is numbered with 0, this can be used for a "home" link on top | ||||||||||||||||||||||||||||
| 139 | of the list. The list may be restricted by specifying C<restrict>. If | ||||||||||||||||||||||||||||
| 140 | tolevel is less than fromlevel, then an empty list is returned. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub ancestors { | ||||||||||||||||||||||||||
|
Subroutine
ancestors: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | my @l = $self->{ObjDB}->pathobjects_with_cache($self->current_id($params), undef, $self->{POCache}); | |||||||||||||||||||||||||||
| 148 | 0 | pop @l; # delete last in list (the object itself); | |||||||||||||||||||||||||||
| 149 | 0 | $self->objify_list(\@l); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if (defined $params->{fromlevel}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if (defined $params->{tolevel}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | @l = @l[$params->{fromlevel} .. $params->{tolevel}]; | |||||||||||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||||||||||
| 155 | 0 | @l = @l[$params->{fromlevel} .. $#l]; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } elsif (defined $params->{tolevel}) { | ||||||||||||||||||||||||||||
| 158 | 0 | @l = @l[0 .. $params->{tolevel}]; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $self->restrict($params, \@l); | |||||||||||||||||||||||||||
| 162 | 0 | [@l]; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item parent([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Return the parent of the current object, or of the object with id | ||||||||||||||||||||||||||||
| 168 | C<objid>. Note that it is possible in the C<WE::DB::Obj> database to | ||||||||||||||||||||||||||||
| 169 | have more than one parent, nevertheless only one parent is returned. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =cut | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub parent { | ||||||||||||||||||||||||||
|
Subroutine
parent: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | my $obj = $self->current_object($params); | |||||||||||||||||||||||||||
| 177 | 0 | my $objdb = $self->{ObjDB}; | |||||||||||||||||||||||||||
| 178 | 0 | my(@l) = ($objdb->parents($obj))[0]; | |||||||||||||||||||||||||||
| 179 | 0 | $self->objify_list(\@l); | |||||||||||||||||||||||||||
| 180 | 0 | $self->restrict($params, \@l); | |||||||||||||||||||||||||||
| 181 | 0 | $l[0]; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =item level([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Return the level of the current object, or of the object with id | ||||||||||||||||||||||||||||
| 187 | C<objid>. The root of the site has level = 0. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =cut | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub level { | ||||||||||||||||||||||||||
|
Subroutine
level: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 193 | 0 | scalar @{ $self->ancestors(@_) }; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =item toplevel_children([sort = sortmethod, restrict = restrictmethod]) | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Return a list of sorted toplevel children. Normally, the sequence | ||||||||||||||||||||||||||||
| 199 | order is used but the sorting can be changed by specifying C<sort>. | ||||||||||||||||||||||||||||
| 200 | The list may be restricted by specifying C<restrict>. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =cut | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub toplevel_children { | ||||||||||||||||||||||||||
|
Subroutine
toplevel_children: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $params->{'level'} = 1; | |||||||||||||||||||||||||||
| 208 | 0 | $self->siblings($params); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =item siblings([[objid = id | name = name], level = level, sort = sortmethod, restrict => restrictmethod]) | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | Get the siblings of the current object, or of the object with id | ||||||||||||||||||||||||||||
| 214 | C<objid>. The siblings are sorted by the sortmethod in C<sort> and | ||||||||||||||||||||||||||||
| 215 | can be restricted with C<restrict>. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | If C<level> is specified, the siblings of the ancestor of the current | ||||||||||||||||||||||||||||
| 218 | object in the specified level are returned. The level can also be | ||||||||||||||||||||||||||||
| 219 | specified as a negative number; this means how many levels up from the | ||||||||||||||||||||||||||||
| 220 | current position should be used. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub siblings { | ||||||||||||||||||||||||||
|
Subroutine
siblings: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 226 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 0 | my $objid = $self->current_id($params); | |||||||||||||||||||||||||||
| 228 | 0 | my $objdb = $self->{ObjDB}; | |||||||||||||||||||||||||||
| 229 | 0 | my $pid; | |||||||||||||||||||||||||||
| 230 | my @l; | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (defined $params->{level}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | my @ancestors = $objdb->pathobjects_with_cache($objid, undef, $self->{POCache}); | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ($params->{level} =~ /^\d/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 234 | 0 | $pid = $ancestors[$params->{level}-1]; # XXX -1 ??? | |||||||||||||||||||||||||||
| 235 | } elsif ($params->{level} =~ /^-(\d+)$/) { | ||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if (-($params->{level}-2) > scalar @ancestors + 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 237 | 0 | return $self->error("Level above root object"); | |||||||||||||||||||||||||||
| 238 | } elsif (-($params->{level}-2) == scalar @ancestors + 1) { | ||||||||||||||||||||||||||||
| 239 | # the root object itself | ||||||||||||||||||||||||||||
| 240 | 0 | @l = $ancestors[0]; | |||||||||||||||||||||||||||
| 241 | 0 | $self->objify_list(\@l); | |||||||||||||||||||||||||||
| 242 | 0 | $self->restrict($params, \@l); | |||||||||||||||||||||||||||
| 243 | # no sorting necessary :-) | ||||||||||||||||||||||||||||
| 244 | 0 | return @l; | |||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||
| 246 | 0 | $pid = $ancestors[$params->{level}-2] | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | } else { | ||||||||||||||||||||||||||||
| 249 | 0 | return $self->error("Invalid level specifier: $params->{level}"); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||
| 252 | 0 | $pid = ($objdb->parent_ids($objid))[0]; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | 0 | @l = $objdb->children($pid); | |||||||||||||||||||||||||||
| 255 | 0 | $self->objify_list(\@l); | |||||||||||||||||||||||||||
| 256 | 0 | $self->restrict($params, \@l); | |||||||||||||||||||||||||||
| 257 | 0 | $self->sort($params, \@l); | |||||||||||||||||||||||||||
| 258 | 0 | [@l]; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =item children([[objid = id | name = name], sort = sortmethod, restrict => restrictmethod]) | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Get the children of the current object, or of the object with id | ||||||||||||||||||||||||||||
| 264 | C<objid>. The children are sorted by the sortmethod in C<sort> and | ||||||||||||||||||||||||||||
| 265 | can be restricted with C<restrict>. | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub children { | ||||||||||||||||||||||||||
|
Subroutine
children: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 270 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | my $obj = $self->current_object($params); | |||||||||||||||||||||||||||
| 273 | 0 | my @l = $self->{ObjDB}->children($obj); | |||||||||||||||||||||||||||
| 274 | 0 | $self->objify_list(\@l); | |||||||||||||||||||||||||||
| 275 | 0 | $self->restrict($params, \@l); | |||||||||||||||||||||||||||
| 276 | 0 | $self->sort($params, \@l); | |||||||||||||||||||||||||||
| 277 | 0 | [@l]; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =item siblings_or_children([...]); | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | Often, siblings are used if the object is a document and children are | ||||||||||||||||||||||||||||
| 283 | used if the object is a folder. This convenience method uses the | ||||||||||||||||||||||||||||
| 284 | appropriate method. The arguments are the same as in C<siblings> or | ||||||||||||||||||||||||||||
| 285 | C<children>. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub siblings_or_children { | ||||||||||||||||||||||||||
|
Subroutine
siblings_or_children: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 291 | 0 | ▶ | my $params = ref($_[$#_]) eq 'HASH' ? pop(@_) : { }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | my $obj = $self->current_object($params); | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($obj->is_doc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | $self->siblings($params); | |||||||||||||||||||||||||||
| 295 | } else { | ||||||||||||||||||||||||||||
| 296 | 0 | $self->children($params); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =item restrict($params, $listref) | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | Internal method to restrict the passed array reference according to | ||||||||||||||||||||||||||||
| 303 | the C<<$params->{restrict}>> subroutine. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | The value of the C<restrict> parameter should be the name of a method | ||||||||||||||||||||||||||||
| 306 | in the C<WE_Frontend::Plugin::Navigation::Object> class. The object is | ||||||||||||||||||||||||||||
| 307 | accepted if the returned value is true. Example for an user-defined | ||||||||||||||||||||||||||||
| 308 | method (although subclassing would be the cleaner solution): | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | package WE_Frontend::Plugin::Navigation::Object; | ||||||||||||||||||||||||||||
| 311 | sub my_restrict { | ||||||||||||||||||||||||||||
| 312 | my $o = shift; | ||||||||||||||||||||||||||||
| 313 | # restrict to objects with Id less than 5 | ||||||||||||||||||||||||||||
| 314 | $o->o->Id < 5; | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub restrict { | ||||||||||||||||||||||||||
|
Subroutine
restrict: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 320 | 0 | my($self, $params, $listref) = @_; | |||||||||||||||||||||||||||
| 321 | 0 | my $sub = $params->{restrict}; | |||||||||||||||||||||||||||
| 322 | 0 | ▶ | return if !$sub || !@$listref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sub and @$listref
MC/DC0%0/2
$sub and @$listref
$sub
@$listref
Truth table0%0/3
A and B
A= $subB= @$listref
| |||||||||||||||||||||||||||||
| 323 | 0 | @$listref = grep { $_->$sub() } @$listref; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =item sort($params, $listref) | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | Internal method to sort the passed array reference according to | ||||||||||||||||||||||||||||
| 329 | the C<<$params->{sort}>> subroutine. | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | The value of the C<sort> parameter should be the name of a method in | ||||||||||||||||||||||||||||
| 332 | the C<WE_Frontend::Plugin::Navigation> class. This method takes to | ||||||||||||||||||||||||||||
| 333 | arguments C<$a> and C<$b>, both | ||||||||||||||||||||||||||||
| 334 | C<WE_Frontend::Plugin::Navigation::Object> objects which should be | ||||||||||||||||||||||||||||
| 335 | compared. The returned value should be -1, 0, or 1, just as in the | ||||||||||||||||||||||||||||
| 336 | C<sort> function. Example for an user-defined method (although | ||||||||||||||||||||||||||||
| 337 | subclassing would be the cleaner solution): | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | package WE_Frontend::Plugin::Navigation; | ||||||||||||||||||||||||||||
| 340 | sub my_sort { | ||||||||||||||||||||||||||||
| 341 | my($self, $a, $b) = @_; | ||||||||||||||||||||||||||||
| 342 | # sort by title | ||||||||||||||||||||||||||||
| 343 | WE::Util::LangString::langstring($a->o->Title) cmp WE::Util::LangString::langstring($b->o->Title); | ||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =cut | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub sort { | ||||||||||||||||||||||||||
|
Subroutine
sort: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 349 | 0 | my($self, $params, $listref) = @_; | |||||||||||||||||||||||||||
| 350 | 0 | my $sub = $params->{sort}; | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | return if !$sub || !@$listref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sub and @$listref
MC/DC0%0/2
$sub and @$listref
$sub
@$listref
Truth table0%0/3
A and B
A= $subB= @$listref
| |||||||||||||||||||||||||||||
| 352 | 0 | @$listref = sort { $self->$sub($a,$b) } @$listref; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =item current_object([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | Return the current active object as a C<WE::Obj> object. See also the | ||||||||||||||||||||||||||||
| 358 | C<self> method. | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =cut | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub current_object { | ||||||||||||||||||||||||||
|
Subroutine
current_object: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 363 | 0 | my($self, $params) = @_; | |||||||||||||||||||||||||||
| 364 | 0 | my $id = $self->current_id($params); | |||||||||||||||||||||||||||
| 365 | # XXX check for error? | ||||||||||||||||||||||||||||
| 366 | 0 | my $objdb = $self->{ObjDB}; | |||||||||||||||||||||||||||
| 367 | 0 | my $obj = $objdb->get_object($id); | |||||||||||||||||||||||||||
| 368 | 0 | ▶ | if (!$obj) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | return $self->error("Can't get object with id <$id> from database <" . $objdb->DBFile . ">"); | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | 0 | $obj; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =item current_id([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Return the current active id. The object is identified in this order: | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =over | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | =item C<objid> in this method call | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =item C<name> in this method call | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =item C<objid> parameter in the C<Navigation> C<USE> directive | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =item C<objid> template variable (as specified in the C<< | ||||||||||||||||||||||||||||
| 387 | Template->new >> call) | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =back | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =cut | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub current_id { | ||||||||||||||||||||||||||
|
Subroutine
current_id: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 394 | 0 | my($self, $params) = @_; | |||||||||||||||||||||||||||
| 395 | 0 | my $id; | |||||||||||||||||||||||||||
| 396 | 0 | ▶ | if (defined $params->{objid}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 397 | 0 | $id = $params->{objid}; | |||||||||||||||||||||||||||
| 398 | } elsif (defined $params->{name}) { | ||||||||||||||||||||||||||||
| 399 | 0 | $id = $self->{ObjDB}->name_to_objid($params->{name}); | |||||||||||||||||||||||||||
| 400 | } elsif (defined $self->{ObjID}) { | ||||||||||||||||||||||||||||
| 401 | 0 | $id = $self->{ObjID}; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if (!defined $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | return $self->error("No object id defined. Please define it in either: | |||||||||||||||||||||||||||
| 405 | * as an objid parameter in the current method call | ||||||||||||||||||||||||||||
| 406 | * as an name parameter (with an existing name) in the current method call | ||||||||||||||||||||||||||||
| 407 | * as an objid parameter in the USE directive | ||||||||||||||||||||||||||||
| 408 | * as an objid template variable | ||||||||||||||||||||||||||||
| 409 | "); | ||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | 0 | $id; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =item self([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | Return the current active object as a B<...::Navigation::Object> object. | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | =cut | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub self { | ||||||||||||||||||||||||||
|
Subroutine
self: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 421 | 0 | my($self, $params) = @_; | |||||||||||||||||||||||||||
| 422 | 0 | my $class = $self->Object; | |||||||||||||||||||||||||||
| 423 | 0 | $class->new($self->current_object($params), $self); | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =item get_object([[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | This is an alias for B<self>, but uses a more "logical" name if an | ||||||||||||||||||||||||||||
| 429 | object is retrieved by id or name. | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =cut | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 1 | *get_object = \&self; | |||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =item is_self([$testobj | $testobjid], [[objid = id | name = name]]) | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | Return true if the given C<$testobj> (object) or C<$testobjid> (id) is | ||||||||||||||||||||||||||||
| 438 | the current object. You can pass another C<objid> instead of the | ||||||||||||||||||||||||||||
| 439 | current object. =cut | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =cut | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | ▶ | sub is_self { | ||||||||||||||||||||||||||
|
Subroutine
is_self: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 444 | 0 | my($self, $id, $params) = @_; | |||||||||||||||||||||||||||
| 445 | 0 | $self->idify_params($id); | |||||||||||||||||||||||||||
| 446 | 0 | my $current_id = $self->current_id($params); | |||||||||||||||||||||||||||
| 447 | 0 | $id eq $current_id; | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =item equals([$testobj | $testobjid], [objid = id | name = name]) | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | The same as C<is_self>, only that either C<objid> or C<name> are | ||||||||||||||||||||||||||||
| 453 | mandatory. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | Example: | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | [% IF n.equals(testobjid, objid = otherobjid) %] | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | =cut | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub equals { | ||||||||||||||||||||||||||
|
Subroutine
equals: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 462 | 0 | my($self, $id, $params) = @_; | |||||||||||||||||||||||||||
| 463 | 0 | ▶ | if (!exists $params->{objid} && !exists $params->{name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params->{"objid"} or exists $params->{"name"}
MC/DC0%0/2
exists $params->{"objid"} or exists $params->{"name"}
exists $params->{"objid"}
exists $params->{"name"}
Truth table0%0/3
A or B
A= exists $params->{"objid"}B= exists $params->{"name"}
| |||||||||||||||||||||||||||||
| 464 | 0 | die "Either objid or name are mandatory for the equals method"; | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | 0 | $self->is_self($id, $params); | |||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | =item is_ancestor([$testobj | $testobjid], [objid => id]) | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | Return true if the given C<$testobj> (object) or C<$testobjid> (id) is | ||||||||||||||||||||||||||||
| 472 | an ancestor of the current object. You can pass another C<objid> | ||||||||||||||||||||||||||||
| 473 | instead of the current object. The current object is not considered an | ||||||||||||||||||||||||||||
| 474 | ancestor of itself. | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =cut | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 0 | ▶ | sub is_ancestor { | ||||||||||||||||||||||||||
|
Subroutine
is_ancestor: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 479 | 0 | my($self, $objid, $params) = @_; | |||||||||||||||||||||||||||
| 480 | 0 | $self->idify_params($objid); | |||||||||||||||||||||||||||
| 481 | 0 | my $current_id = $self->current_id($params); | |||||||||||||||||||||||||||
| 482 | 0 | ▶ | return 0 if $objid eq $current_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 0 | for my $o ($self->{ObjDB}->pathobjects_with_cache($current_id, undef, $self->{POCache})) { | |||||||||||||||||||||||||||
| 484 | 0 | ▶ | return 1 if ($objid eq $o->Id); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | 0 | 0; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | =item object_by_name($name) | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | Return an object by C<$name>. | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | =cut | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | 0 | ▶ | sub object_by_name { | ||||||||||||||||||||||||||
|
Subroutine
object_by_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 496 | 0 | my($self, $name) = @_; | |||||||||||||||||||||||||||
| 497 | 0 | my $id = $self->{ObjDB}->name_to_objid($name); | |||||||||||||||||||||||||||
| 498 | 0 | ▶ | if (defined $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 0 | return $self->self({objid => $id}); | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | 0 | return $self->error("Can't get object by name $name"); | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | =item Root | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | Return reference to root database. | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | =cut | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub Root { $_[0]->{ObjDB}->Root } | ||||||||||||||||||||||||||
|
Subroutine
Root: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | =item ObjDB | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | Return reference to the object database. | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | =cut | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub ObjDB { $_[0]->{ObjDB} } | ||||||||||||||||||||||||||
|
Subroutine
ObjDB: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | =item Object | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | Return the class name for the navigation objects. This can be | ||||||||||||||||||||||||||||
| 523 | overridden in inherited classes. | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | =cut | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 0 | ▶ | sub Object { | ||||||||||||||||||||||||||
|
Subroutine
Object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 528 | 0 | "WE_Frontend::Plugin::Navigation::Object"; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | =back | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | =head2 MEMBERS | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | Remember that there is no visible distinction in the Template-Toolkit | ||||||||||||||||||||||||||||
| 536 | between accessing members and methods. | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | =over | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | =item Context | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | The C<WEsiteinfo> context. | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | =item ObjDB | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | A reference to the object database (C<WE::DB::Obj>). | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | =back | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | =head2 INTERNAL METHODS | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | =over | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | =item objify_list($listref) | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | Internal method to create from a list of C<WE::Obj> objects a list of | ||||||||||||||||||||||||||||
| 557 | Navigation objects (see the C<Object> method). The passed parameter | ||||||||||||||||||||||||||||
| 558 | C<$listref> will be changed. | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 0 | ▶ | sub objify_list { | ||||||||||||||||||||||||||
|
Subroutine
objify_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 563 | 0 | my($self, $objlistref) = @_; | |||||||||||||||||||||||||||
| 564 | 0 | my $class = $self->Object; | |||||||||||||||||||||||||||
| 565 | 0 | @$objlistref = map { $class->new($_, $self) } @$objlistref; | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =item objectify_params($obj_or_id, $obj_or_id, ...) | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | Turn the given arguments from an object id or C<WE::Obj> object into | ||||||||||||||||||||||||||||
| 571 | an C<WE_Frontend::Plugin::Navigation::Object> object. | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | =cut | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 0 | ▶ | sub objectify_params { | ||||||||||||||||||||||||||
|
Subroutine
objectify_params: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 576 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 577 | 0 | my $class = $self->Object; | |||||||||||||||||||||||||||
| 578 | 0 | my $objdb = $self->{ObjDB}; | |||||||||||||||||||||||||||
| 579 | 0 | for (@_) { | |||||||||||||||||||||||||||
| 580 | 0 | ▶ | if (/^\d+$/) { # treat as object id | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 581 | 0 | $_ = $objdb->get_object($_); | |||||||||||||||||||||||||||
| 582 | } elsif (UNIVERSAL::isa($_, $class)) { | ||||||||||||||||||||||||||||
| 583 | # do nothing | ||||||||||||||||||||||||||||
| 584 | } elsif (UNIVERSAL::isa($_, "WE::Obj")) { | ||||||||||||||||||||||||||||
| 585 | 0 | $_ = $class->new($_, $self); | |||||||||||||||||||||||||||
| 586 | } else { | ||||||||||||||||||||||||||||
| 587 | 0 | warn "Can't interpret $_ in objectify_params"; | |||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | =item idify_params($obj_or_id, ....) | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | Turn the given arguments from an object id or C<WE::Obj> object into | ||||||||||||||||||||||||||||
| 595 | an object id. | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | =cut | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 0 | ▶ | sub idify_params { | ||||||||||||||||||||||||||
|
Subroutine
idify_params: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 600 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 601 | 0 | my $class = $self->Object; | |||||||||||||||||||||||||||
| 602 | 0 | my $objdb = $self->{ObjDB}; | |||||||||||||||||||||||||||
| 603 | 0 | for (@_) { | |||||||||||||||||||||||||||
| 604 | 0 | ▶ | if (/^\d+$/) { # treat as object id | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 605 | # do nothing | ||||||||||||||||||||||||||||
| 606 | } elsif (UNIVERSAL::isa($_, $class)) { | ||||||||||||||||||||||||||||
| 607 | 0 | $_ = $_->o->Id; | |||||||||||||||||||||||||||
| 608 | } elsif (UNIVERSAL::isa($_, "WE::Obj")) { | ||||||||||||||||||||||||||||
| 609 | 0 | $_ = $_->Id; | |||||||||||||||||||||||||||
| 610 | } else { | ||||||||||||||||||||||||||||
| 611 | 0 | warn "Can't interpret $_ in idify_params"; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | # hmmm... the default error() method does not throw an exception | ||||||||||||||||||||||||||||
| 617 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 618 | 0 | require Carp; | |||||||||||||||||||||||||||
| 619 | 0 | Carp::confess($_[1]); | |||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 623 | 0 | my($self, $extra) = @_; | |||||||||||||||||||||||||||
| 624 | 0 | my $out = "Dump $self:\n"; | |||||||||||||||||||||||||||
| 625 | 0 | require WE::Util::LangString; | |||||||||||||||||||||||||||
| 626 | 0 | ▶ | while(my($k,$v) = each %$self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 627 | 0 | $out .= "$k => " . WE::Util::LangString::langstring($v) . "\n"; | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | 0 | ▶ | $out .= "\n$extra" if defined $extra; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 630 | 0 | $out .= "\n"; | |||||||||||||||||||||||||||
| 631 | 0 | warn $out; | |||||||||||||||||||||||||||
| 632 | 0 | ""; | |||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | # XXX documentation pending | ||||||||||||||||||||||||||||
| 636 | 0 | ▶ | sub reset_cache { | ||||||||||||||||||||||||||
|
Subroutine
reset_cache: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 637 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 638 | 0 | $self->{POCache} = {}; | |||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | ## Debugging aid: | ||||||||||||||||||||||||||||
| 642 | # sub DESTROY { | ||||||||||||||||||||||||||||
| 643 | # my $self = shift; | ||||||||||||||||||||||||||||
| 644 | # warn $self->{ObjDB}->{CH} if defined $self->{ObjDB} && defined $self->{ObjDB}->{CH}; | ||||||||||||||||||||||||||||
| 645 | # } | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | 1 | 1; | |||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | __END__ | ||||||||||||||||||||||||||||