diff options
author | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2011-11-25 15:23:10 +0000 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2011-11-25 15:23:10 +0000 |
commit | 75f20230821c883d919d6a3f84d3930862bb8fd7 (patch) | |
tree | 03933dd7cd89f6c910b6eae5e394c9e22bc2e2a9 /lib/Data | |
parent | changes bump for CPAN release (diff) | |
download | data-multivalued-75f20230821c883d919d6a3f84d3930862bb8fd7.tar.gz data-multivalued-75f20230821c883d919d6a3f84d3930862bb8fd7.tar.bz2 data-multivalued-75f20230821c883d919d6a3f84d3930862bb8fd7.zip |
minor fixes after seeing it on CPAN
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/MultiValued/AttributeAccessors.pm | 47 | ||||
-rw-r--r-- | lib/Data/MultiValued/AttributeTrait.pm | 9 | ||||
-rw-r--r-- | lib/Data/MultiValued/Exceptions.pm | 58 | ||||
-rw-r--r-- | lib/Data/MultiValued/RangeContainer.pm | 13 | ||||
-rw-r--r-- | lib/Data/MultiValued/Ranges.pm | 12 | ||||
-rw-r--r-- | lib/Data/MultiValued/TagContainer.pm | 4 | ||||
-rw-r--r-- | lib/Data/MultiValued/Tags.pm | 4 | ||||
-rw-r--r-- | lib/Data/MultiValued/TagsAndRanges.pm | 9 |
8 files changed, 132 insertions, 24 deletions
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<Moose::Meta::Method::Accessor>, 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<set_multi_value>, C<get_multi_value>, +C<has_multi_value>, C<clear_multi_value>, 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<set_multi_value>, C<get_multi_value>, +C<has_multi_value>, C<clear_multi_value>, 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<Class::MOP::Attribute> 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<Data::MultiValued::Exceptions::NotFound> exception -that may be thrown by the multi-value object, but re-throws any other -exception. +This traps the +L<Data::MultiValued::Exceptions::NotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::NotFound> +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<Throwable::Error> +as a base class. + +=head1 CLASSES + +=head2 C<Data::MultiValued::Exceptions::NotFound> + +Base class for "not found" errors. Has a C<value> 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<Data::MultiValued::Exceptions::TagNotFound> + +Subclass of L</Data::MultiValued::Exceptions::NotFound>, 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<Data::MultiValued::Exceptions::RangeNotFound> + +Subclass of L</Data::MultiValued::Exceptions::NotFound>, 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<Data::MultiValued::Exceptions::BadRange> + +Thrown when an invalid range is supplied to a method. An invalid range +is a range with C<from> greater than C<to>. + +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<Data::MultiValued::Exceptions::RangeNotFound> exception if no range -includes the point. +L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound> +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<Data::MultiValued::Exceptions::BadRange> if -C<< $min > $max >>. +and returns it. Throws +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +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<Data::MultiValued::Exceptions::BadRange> if C<< $min > $max >>. +Throws +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +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<Data::MultiValued::Exceptions::BadRange> if C<< $min > $max >>. +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +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<Data::MultiValued::Exceptions::RangeNotFound> exception if no ranges -exist in this object that include the point (remember that a range -does not include its C<to> point). +L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound> +exception if no ranges exist in this object that include the point +(remember that a range does not include its C<to> point). A C<< at => undef >> means "at -Inf". Not passing in C<at> is equivalent to passing C<undef>. @@ -114,7 +115,8 @@ sub get { $obj->clear({ from => $min, to => $max }); Deletes all values for the given range. Throws -L<Data::MultiValued::Exceptions::BadRange> if C<< $min > $max >>. +L<Data::MultiValued::Exceptions::BadRange|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::BadRange> +if C<< $min > $max >>. A C<< from => undef >> means "from -Inf", and a C<< to => undef >> means "to +Inf". Not passing in C<from> or C<to> 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<Data::MultiValued::Exceptions::TagNotFound> exception if the tag -does not exists in this object. +L<Data::MultiValued::Exceptions::TagNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::TagNotFound> +exception if the tag does not exists in this object. Not passing in a C<tag> 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<Data::MultiValued::Exceptions::TagNotFound> exception if the tag -does not exists in this object. +L<Data::MultiValued::Exceptions::TagNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::TagNotFound> +exception if the tag does not exists in this object. Not passing in a C<tag> 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<Data::MultiValued::Exceptions::RangeNotFound> exception if no ranges -exist in this object that include the point, and -L<Data::MultiValued::Exceptions::TagNotFound> exception if the tag -does not exists in this object. +L<Data::MultiValued::Exceptions::RangeNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::RangeNotFound> +exception if no ranges exist in this object that include the point, +and +L<Data::MultiValued::Exceptions::TagNotFound|Data::MultiValued::Exceptions/Data::MultiValued::Exceptions::TagNotFound> +exception if the tag does not exists in this object. See L<Data::MultiValued::Tags/get> and L<Data::MultiValued::Ranges/get> for more details. |