From 921db9613fd31014029454e94a365f662d45b2e1 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 13 May 2013 10:36:25 +0200 Subject: [PATCH] =?utf8?q?RequirementSpec(Item):=20Arrays=20nur=20als=20Re?= =?utf8?q?ferenz=20zur=C3=BCckgeben?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Innerhalb vom Template-Toolkit kann ansonsten Merkwürdiges passieren. Weist man das Ergebnis einer Variablen zu, so geschieht dies offensichtlich im Array-Kontext. Dadurch sind aber Tests mit var.size plötzlich falsch... [% SET blocks = rspec.text_blocks_sorted(output_position=0) %] [% IF blocks.size %] ...greift auch, wenn keine Blöcke für diese Position existieren --- SL/DB/RequirementSpec.pm | 27 +++++++++++++-------------- SL/DB/RequirementSpecItem.pm | 8 +++----- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/SL/DB/RequirementSpec.pm b/SL/DB/RequirementSpec.pm index d8329b93a..f7fd2d525 100644 --- a/SL/DB/RequirementSpec.pm +++ b/SL/DB/RequirementSpec.pm @@ -58,7 +58,7 @@ sub text_blocks_sorted { @text_blocks = grep { $_->output_position == $params{output_position} } @text_blocks if exists $params{output_position}; @text_blocks = sort { $a->position <=> $b->position } @text_blocks; - return wantarray ? @text_blocks : \@text_blocks; + return \@text_blocks; } sub sections_sorted { @@ -66,8 +66,7 @@ sub sections_sorted { croak "This sub is not a writer" if @rest; - my @sections = sort { $a->position <=> $b->position } grep { !$_->parent_id } @{ $self->items }; - return wantarray ? @sections : \@sections; + return [ sort { $a->position <=> $b->position } grep { !$_->parent_id } @{ $self->items } ]; } sub sections { §ions_sorted; } @@ -85,7 +84,7 @@ sub versioned_copies_sorted { @copies = grep { $_->version->version_number <= $params{max_version_number} } @copies if $params{max_version_number}; @copies = sort { $a->version->version_number <=> $b->version->version_number } @copies; - return wantarray ? @copies : \@copies; + return \@copies; } sub create_copy { @@ -405,16 +404,17 @@ An alias for L. =item C -Returns a list of requirement spec items that +Returns an array reference of requirement spec items that do not have +a parent -- meaning that are sections. This is not a writer. Use the C relationship for that. =item C -Returns an array (or an array reference depending on context) of text -blocks sorted by their positional column in ascending order. If the -C parameter is given then only the text blocks -belonging to that C are returned. +Returns an array reference of text blocks sorted by their positional +column in ascending order. If the C parameter is +given then only the text blocks belonging to that C +are returned. =item C @@ -423,11 +423,10 @@ messages (if any). =item C -Returns an array (or an array reference depending on context) of -versioned copies sorted by their version number in ascending order. If -the C parameter is given then only the versioned -copies whose version number is less than or equal to -C are returned. +Returns an array reference of versioned copies sorted by their version +number in ascending order. If the C parameter is +given then only the versioned copies whose version number is less than +or equal to C are returned. =back diff --git a/SL/DB/RequirementSpecItem.pm b/SL/DB/RequirementSpecItem.pm index 5e7d46c91..d07ed04c8 100644 --- a/SL/DB/RequirementSpecItem.pm +++ b/SL/DB/RequirementSpecItem.pm @@ -104,8 +104,7 @@ sub children_sorted { croak "Not a writer" if @args; - my @children = sort { $a->position <=> $b->position } $self->children; - return wantarray ? @children : \@children; + return [ sort { $a->position <=> $b->position } $self->children ]; } sub section { @@ -150,9 +149,8 @@ Returns the C for children of C<$self>. =item C -Returns an array (or an array reference depending on context) of -direct children (not of grandchildren) for C<$self> ordered by their -positional column in ascending order. +Returns an array reference of direct children (not of grandchildren) +for C<$self> ordered by their positional column in ascending order. =item C
-- 2.20.1