From 75f20230821c883d919d6a3f84d3930862bb8fd7 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Fri, 25 Nov 2011 15:23:10 +0000 Subject: minor fixes after seeing it on CPAN --- dist.ini | 2 +- lib/Data/MultiValued/AttributeAccessors.pm | 47 ++++++++++++++++++++++++ lib/Data/MultiValued/AttributeTrait.pm | 9 ++--- lib/Data/MultiValued/Exceptions.pm | 58 ++++++++++++++++++++++++++++-- lib/Data/MultiValued/RangeContainer.pm | 13 ++++--- lib/Data/MultiValued/Ranges.pm | 12 ++++--- lib/Data/MultiValued/TagContainer.pm | 4 +-- lib/Data/MultiValued/Tags.pm | 4 +-- lib/Data/MultiValued/TagsAndRanges.pm | 9 ++--- 9 files changed, 133 insertions(+), 25 deletions(-) diff --git a/dist.ini b/dist.ini index 6933499..db3d702 100644 --- a/dist.ini +++ b/dist.ini @@ -1,7 +1,7 @@ name = Data-MultiValued author = Gianni Ceccarelli license = Perl_5 -copyright_holder = Net-a-porter.com +copyright_holder = Net-a-Porter.com copyright_year = 2011 abstract = Handle values with tags and validity ranges diff --git a/lib/Data/MultiValued/AttributeAccessors.pm b/lib/Data/MultiValued/AttributeAccessors.pm index cac3538..64063da 100644 --- a/lib/Data/MultiValued/AttributeAccessors.pm +++ b/lib/Data/MultiValued/AttributeAccessors.pm @@ -4,8 +4,39 @@ use warnings; use base 'Moose::Meta::Method::Accessor'; use Carp 'confess'; +# ABSTRACT: method meta-class for multi-valued attribute accessors + +=head1 DESCRIPTION + +Subclass of L, generates non-inlined +(patches welcome) accessors for multi-valued attributes. + +=head1 METHDOS + +=head2 C<_instance_is_inlinable> + +Returns C<0> to prevent attempts to inline the accessor methods. + +=cut + sub _instance_is_inlinable { 0 } +=head2 C<_generate_accessor_method> + +=head2 C<_generate_reader_method> + +=head2 C<_generate_writer_method> + +=head2 C<_generate_predicate_method> + +=head2 C<_generate_clearer_method> + +Delegate to C, C, +C, C, passing empty options +(i.e. no tags, no ranges). + +=cut + sub _generate_accessor_method { my $self = shift; my $attr = $self->associated_attribute; @@ -56,6 +87,22 @@ sub _generate_clearer_method { }; } +=head2 C<_generate_multi_accessor_method> + +=head2 C<_generate_multi_reader_method> + +=head2 C<_generate_multi_writer_method> + +=head2 C<_generate_multi_predicate_method> + +=head2 C<_generate_multi_clearer_method> + +Delegate to C, C, +C, C, passing C<$_[1]> as options +and C<$_[2]> as values. + +=cut + sub _generate_multi_accessor_method { my $self = shift; my $attr = $self->associated_attribute; diff --git a/lib/Data/MultiValued/AttributeTrait.pm b/lib/Data/MultiValued/AttributeTrait.pm index fd180ed..263b6ee 100644 --- a/lib/Data/MultiValued/AttributeTrait.pm +++ b/lib/Data/MultiValued/AttributeTrait.pm @@ -67,7 +67,7 @@ sub _build_full_storage_slot { shift->name . '__MULTIVALUED_STORAGE__' } The names to use for the various additional accessors. See L for details. These default to -C<"multi_$name"> where C<$name> is the name of the corresponding +C<"${name}_multi"> where C<$name> is the name of the corresponding non-multi accessor. So, for example, has stuff => ( @@ -252,9 +252,10 @@ Retrieves a value from the multi-value object, and stores it in the regular slot in the instance. If the value is not found, clears the slot. -This traps the L exception -that may be thrown by the multi-value object, but re-throws any other -exception. +This traps the +L +exception that may be thrown by the multi-value object, but re-throws +any other exception. =cut diff --git a/lib/Data/MultiValued/Exceptions.pm b/lib/Data/MultiValued/Exceptions.pm index 8d444c0..6495780 100644 --- a/lib/Data/MultiValued/Exceptions.pm +++ b/lib/Data/MultiValued/Exceptions.pm @@ -1,4 +1,21 @@ package Data::MultiValued::Exceptions; + +# ABSTRACT: exception classes + +=head1 DESCRIPTION + +This module defines a few exception classes, using L +as a base class. + +=head1 CLASSES + +=head2 C + +Base class for "not found" errors. Has a C attribute, +containing the value that was not found. + +=cut + package Data::MultiValued::Exceptions::NotFound;{ use Moose; extends 'Throwable::Error'; @@ -16,8 +33,19 @@ sub as_string { return $str; } - } + +=head2 C + +Subclass of L, for +tags. Stringifies to: + + tag not found: $value + + $stack_trace + +=cut + package Data::MultiValued::Exceptions::TagNotFound;{ use Moose; extends 'Data::MultiValued::Exceptions::NotFound'; @@ -26,14 +54,40 @@ has '+message' => ( default => 'tag not found: ', ); } + +=head2 C + +Subclass of L, for +ranges. Stringifies to: + + no range found for value: $value + + $stack_trace + +=cut + package Data::MultiValued::Exceptions::RangeNotFound;{ use Moose; extends 'Data::MultiValued::Exceptions::NotFound'; has '+message' => ( - default => 'no range found for value ', + default => 'no range found for value: ', ); } + +=head2 C + +Thrown when an invalid range is supplied to a method. An invalid range +is a range with C greater than C. + +Stringifies to: + + invalid range: $from, $to + + $stack_trace + +=cut + package Data::MultiValued::Exceptions::BadRange;{ use Moose; extends 'Throwable::Error'; diff --git a/lib/Data/MultiValued/RangeContainer.pm b/lib/Data/MultiValued/RangeContainer.pm index 83dae11..cc95c45 100644 --- a/lib/Data/MultiValued/RangeContainer.pm +++ b/lib/Data/MultiValued/RangeContainer.pm @@ -44,8 +44,8 @@ has _storage => ( my $value = $obj->get({ at => $point }); Retrieves the range that includes the given point. Throws a -L exception if no range -includes the point. +L +exception if no range includes the point. =cut @@ -123,8 +123,9 @@ sub _partition_slots { Retrieves the range that has the given extremes. If no such range exists, creates a new range, splicing any existing overlapping range, -and returns it. Throws L if -C<< $min > $max >>. +and returns it. Throws +L +if C<< $min > $max >>. =cut @@ -160,7 +161,9 @@ exists, splices any existing overlapping range so that C<< $obj->get({at => $point }) >> for any C<< $min <= $point < $max >> will die. -Throws L if C<< $min > $max >>. +Throws +L +if C<< $min > $max >>. =cut diff --git a/lib/Data/MultiValued/Ranges.pm b/lib/Data/MultiValued/Ranges.pm index 7193df6..3da1594 100644 --- a/lib/Data/MultiValued/Ranges.pm +++ b/lib/Data/MultiValued/Ranges.pm @@ -41,7 +41,8 @@ sub _build__storage { $obj->set({ from => $min, to => $max, value => $the_value }); Stores the given value for the given range. Throws -L if C<< $min > $max >>. +L +if C<< $min > $max >>. The range is defined as C<< Num $x : $min <= $x < $max >>. A C<< from => undef >> means "from -Inf", and a C<< to => undef >> means "to @@ -87,9 +88,9 @@ sub set { my $value = $obj->get({ at => $point }); Retrieves the value for the given point. Throws a -L exception if no ranges -exist in this object that include the point (remember that a range -does not include its C point). +L +exception if no ranges exist in this object that include the point +(remember that a range does not include its C point). A C<< at => undef >> means "at -Inf". Not passing in C is equivalent to passing C. @@ -114,7 +115,8 @@ sub get { $obj->clear({ from => $min, to => $max }); Deletes all values for the given range. Throws -L if C<< $min > $max >>. +L +if C<< $min > $max >>. A C<< from => undef >> means "from -Inf", and a C<< to => undef >> means "to +Inf". Not passing in C or C is equivalent to diff --git a/lib/Data/MultiValued/TagContainer.pm b/lib/Data/MultiValued/TagContainer.pm index bdeca24..f6e5551 100644 --- a/lib/Data/MultiValued/TagContainer.pm +++ b/lib/Data/MultiValued/TagContainer.pm @@ -51,8 +51,8 @@ has _default_tag => ( my $value = $obj->get({ tag => $the_tag }); Retrieves the "storage cell" for the given tag. Throws a -L exception if the tag -does not exists in this object. +L +exception if the tag does not exists in this object. Not passing in a C is equivalent to passing in C<< tag => undef >>. diff --git a/lib/Data/MultiValued/Tags.pm b/lib/Data/MultiValued/Tags.pm index 9c52510..59ebbf5 100644 --- a/lib/Data/MultiValued/Tags.pm +++ b/lib/Data/MultiValued/Tags.pm @@ -66,8 +66,8 @@ sub set { my $value = $obj->get({ tag => $the_tag }); Retrieves the value for the given tag. Throws a -L exception if the tag -does not exists in this object. +L +exception if the tag does not exists in this object. Not passing in a C is equivalent to passing in C<< tag => undef >>. diff --git a/lib/Data/MultiValued/TagsAndRanges.pm b/lib/Data/MultiValued/TagsAndRanges.pm index 204f858..60333c8 100644 --- a/lib/Data/MultiValued/TagsAndRanges.pm +++ b/lib/Data/MultiValued/TagsAndRanges.pm @@ -69,10 +69,11 @@ sub set { my $value = $obj->get({ tag => $the_tag, at => $point }); Retrieves the value for the given tag and point. Throws a -L exception if no ranges -exist in this object that include the point, and -L exception if the tag -does not exists in this object. +L +exception if no ranges exist in this object that include the point, +and +L +exception if the tag does not exists in this object. See L and L for more details. -- cgit v1.2.3