| 1 | package EO::Pair; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use EO::Array; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use base qw( EO::Array ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | our $VERSION = 0.96; | |||||||||
| 10 | |||||||||||
| 11 | 37 | ▶ | sub at { | ||||||||
|
Subroutine
at: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||
| 12 | 37 | my $self = shift; | |||||||||
| 13 | 37 | ▶ | if ($_[0] > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | throw EO::Error::InvalidParameters | |||||||||
| 15 | text => 'pairs cannot have indicies greater than 1'; | ||||||||||
| 16 | } | ||||||||||
| 17 | 37 | $self->SUPER::at( @_ ); | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 6 | ▶ | sub do { | ||||||||
|
Subroutine
do: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 6 | my $self = shift; | |||||||||
| 22 | 6 | my $code = shift; | |||||||||
| 23 | 6 | my $result; | |||||||||
| 24 | { | ||||||||||
| 25 | 6 | local $_ = $self; | |||||||||
| 26 | 6 | $result = $code->( $self ); | |||||||||
| 27 | } | ||||||||||
| 28 | 6 | return $result; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 20 | ▶ | sub key { | ||||||||
|
Subroutine
key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 20 | my $self = shift; | |||||||||
| 33 | 20 | return $self->at( 0, @_ ); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 17 | ▶ | sub value { | ||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 17 | my $self = shift; | |||||||||
| 38 | 17 | return $self->at( 1, @_ ); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 5 | 1; | |||||||||
| 42 | |||||||||||
| 43 | =head1 NAME | ||||||||||
| 44 | |||||||||||
| 45 | EO::Pair - simple pairs for EO. | ||||||||||
| 46 | |||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||
| 48 | |||||||||||
| 49 | use EO::Pair; | ||||||||||
| 50 | |||||||||||
| 51 | my $pair = EO::Pair->new(); | ||||||||||
| 52 | $pair->key( 'foo' ); | ||||||||||
| 53 | $pair->value( 'bar' ); | ||||||||||
| 54 | $pair->do( sub { print $_->key } ); | ||||||||||
| 55 | |||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||
| 57 | |||||||||||
| 58 | C<EO::Pair> provides a simple pair to EO. It is used by the EO::Hash class | ||||||||||
| 59 | primarily. | ||||||||||
| 60 | |||||||||||
| 61 | =head1 CONSTRUCTORS | ||||||||||
| 62 | |||||||||||
| 63 | EO::Pair inherits from EO::Array and provides any constructors that EO::Array | ||||||||||
| 64 | does. | ||||||||||
| 65 | |||||||||||
| 66 | =head1 METHODS | ||||||||||
| 67 | |||||||||||
| 68 | =over 4 | ||||||||||
| 69 | |||||||||||
| 70 | =item key( [KEYNAME] ) | ||||||||||
| 71 | |||||||||||
| 72 | The key method gets and sets the key name of the pair. This is the zeroth | ||||||||||
| 73 | element in the array. | ||||||||||
| 74 | |||||||||||
| 75 | =item value( [VALUE] ) | ||||||||||
| 76 | |||||||||||
| 77 | The value method gets and sets the value of the pair. This is the first\ | ||||||||||
| 78 | element in the array. | ||||||||||
| 79 | |||||||||||
| 80 | =item do( CODE ) | ||||||||||
| 81 | |||||||||||
| 82 | Runs the coderef passed by CODE. Sets $_ and the first argument to CODE as the | ||||||||||
| 83 | pair object. | ||||||||||
| 84 | |||||||||||
| 85 | =back | ||||||||||
| 86 | |||||||||||
| 87 | =head1 AUTHOR | ||||||||||
| 88 | |||||||||||
| 89 | James A. Duncan <jduncan@fotango.com> | ||||||||||
| 90 | |||||||||||
| 91 | =head1 COPYRIGHT | ||||||||||
| 92 | |||||||||||
| 93 | Copyright 2004 Fotango Ltd. All Rights Reserved. | ||||||||||
| 94 | |||||||||||
| 95 | This module is released under the same terms as Perl itself. | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||
| 98 | |||||||||||