Tie-Cycle-1.19/000755 000765 000024 00000000000 12207160017 013454 5ustar00brianstaff000000 000000 Tie-Cycle-1.19/Changes000644 000765 000024 00000004155 12207160015 014752 0ustar00brianstaff000000 000000 Revision history for Perl extension Tie::Cycle. 1.19 - Tue Aug 27 13:20:40 2013 * Update for modern usage, better code * I use this as an example in Mastering Perl, so I shouldn't leave embarrassing practices in the code. :) 1.17 - Fri Jan 30 01:48:06 2009 * Updated the docs for the move to Github * There aren't any code changes 1.16 - Sat Oct 27 20:41:53 2007 * distro cleanups after moving from CVS to SVN 1.15 - Sun Mar 18 23:06:51 2007 * Cleaning dist for new SVN repository * No need to upgrade 1.14 - Tue Jan 9 22:57:17 2007 * updated copyright and license info * no code changes, so no need to upgrade 1.13 - Wed May 17 19:39:21 2006 * Minor cleanups in docs, copyright, and pod testing. No need to upgrade. 1.12 - Tue Mar 8 17:30:50 2005 * Added POD coverage tests. No need to upgrade 1.11 - Mon Jan 3 16:47:10 2005 * Previously, this module refused to work unless the input array had more than one element. What's the point of cycling otherwise? I've removed that restriction, though, because I shouldn't be the one who gets to decide that. A one element array should get a chance to act like any other array. It just happens to have one element. 1.09 - Thu Sep 2 19:56:41 2004 * Just some distribution fixes. No need to upgrade. 1.07 - Sat Jan 31 12:44:16 CST 2004 * No code changes. * Removed dependencies on Test::Manifest, Test::Pod and File::Find::Rule. * Fixed some warnings in tests. 1.06 - Tue Dec 17 14:19:37 2002 * cycle.t test was actually one from Tie::Toggle. it is not the right test. 1.05 - Tue Dec 17 12:49:28 2002 * removed 'require 5.6.0' (perl5.8 complains about v-strings) * beefed up distribution files * no code changes --- no need to install if you already have this 0.05 Wed Aug 14 18:15:01 CDT 2002 * added reset() method for underlying object so Andy Lester can do HTML table tricks * since I was there, I added previous() and next() methods so you can peek at values without affecting the position. 0.02 Wed Jan 24 14:39:24 EST 2001 * minor doc fixes 0.01 Sat Aug 12 23:33:30 2000 * original version; created by h2xs 1.20 with options -AXn Tie::Cycle Tie-Cycle-1.19/examples/000755 000765 000024 00000000000 12207160017 015272 5ustar00brianstaff000000 000000 Tie-Cycle-1.19/lib/000755 000765 000024 00000000000 12207160017 014222 5ustar00brianstaff000000 000000 Tie-Cycle-1.19/LICENSE000644 000765 000024 00000000073 12207160015 014457 0ustar00brianstaff000000 000000 You can use Tie::Cycle under the same terms as Perl itself.Tie-Cycle-1.19/Makefile.PL000644 000765 000024 00000001262 12207160015 015425 0ustar00brianstaff000000 000000 use ExtUtils::MakeMaker 6.46; require 5.008; eval "use Test::Manifest 1.21"; WriteMakefile( 'NAME' => 'Tie::Cycle', 'ABSTRACT' => 'Cycle through a list of values via a scalar', 'VERSION_FROM' => 'lib/Tie/Cycle.pm', 'LICENSE' => 'perl', 'AUTHOR' => 'brian d foy ', 'PREREQ_PM' => { 'Test::More' => '0.95', 'Carp' => '0', }, 'clean' => { FILES => 'Tie-Cycle-*' }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'git@github.com:briandfoy/tie-cycle.git', web => 'https://github.com/briandfoy/tie-cycle', }, }, }, ); Tie-Cycle-1.19/MANIFEST000644 000765 000024 00000000520 12207160017 014602 0ustar00brianstaff000000 000000 Changes examples/README lib/Tie/Cycle.pm LICENSE Makefile.PL MANIFEST MYMETA.json MYMETA.yml README t/cycle.t t/load.t t/one.t t/pod.t t/pod_coverage.t t/test_manifest META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Tie-Cycle-1.19/META.json000664 000765 000024 00000001272 12207160017 015101 0ustar00brianstaff000000 000000 { "abstract" : "Cycle through a list of values via a scalar", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Tie-Cycle", "no_index" : { "directory" : [ "t", "inc" ] }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/briandfoy/tie-cycle" } }, "version" : "1.19" } Tie-Cycle-1.19/META.yml000664 000765 000024 00000000723 12207160017 014731 0ustar00brianstaff000000 000000 --- abstract: 'Cycle through a list of values via a scalar' author: - 'brian d foy ' build_requires: {} dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Tie-Cycle no_index: directory: - t - inc resources: repository: https://github.com/briandfoy/tie-cycle version: 1.19 Tie-Cycle-1.19/MYMETA.json000644 000765 000024 00000001272 12207160016 015344 0ustar00brianstaff000000 000000 { "abstract" : "Cycle through a list of values via a scalar", "author" : [ "brian d foy " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Tie-Cycle", "no_index" : { "directory" : [ "t", "inc" ] }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/briandfoy/tie-cycle" } }, "version" : "1.19" } Tie-Cycle-1.19/MYMETA.yml000644 000765 000024 00000000723 12207160016 015174 0ustar00brianstaff000000 000000 --- abstract: 'Cycle through a list of values via a scalar' author: - 'brian d foy ' build_requires: {} dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Tie-Cycle no_index: directory: - t - inc resources: repository: https://github.com/briandfoy/tie-cycle version: 1.19 Tie-Cycle-1.19/README000644 000765 000024 00000000734 12207160015 014336 0ustar00brianstaff000000 000000 $Id$ You can install this using in the usual Perl fashion perl Makefile.PL make make test make install The documentation is in the module file. Once you install the file, you can read it with perldoc. perldoc Tie::Cycle If you want to read it before you install it, you can use perldoc directly on the module file. perldoc Cycle.pm This module is also in CVS on SourceForge http://sourceforge.net/projects/brian-d-foy/ Enjoy, brian d foy, bdfoy@cpan.orgTie-Cycle-1.19/t/000755 000765 000024 00000000000 12207160017 013717 5ustar00brianstaff000000 000000 Tie-Cycle-1.19/t/cycle.t000644 000765 000024 00000000522 12207160015 015200 0ustar00brianstaff000000 000000 use Test::More; use Tie::Cycle; my @array = qw( A B C ); tie my $cycle, 'Tie::Cycle', \@array; foreach( 0 .. 2 ) { is( $cycle, $array[0], "Cycle is first element, iteration $_" ); is( $cycle, $array[1], "Cycle is second element, iteration $_" ); is( $cycle, $array[2], "Cycle is third element, iteration $_" ); } done_testing(); Tie-Cycle-1.19/t/load.t000644 000765 000024 00000000114 12207160015 015015 0ustar00brianstaff000000 000000 use Test::More 0.95; use_ok( 'Tie::Cycle' ) or BAILOUT(); done_testing(); Tie-Cycle-1.19/t/one.t000644 000765 000024 00000000465 12207160015 014670 0ustar00brianstaff000000 000000 use Test::More 0.95; use Tie::Cycle; my @array = qw( A ); tie my $cycle, 'Tie::Cycle', \@array; is( $cycle, $array[0], "Cycle is first element, iteration 1" ); is( $cycle, $array[0], "Cycle is first element, iteration 2" ); is( $cycle, $array[0], "Cycle is first element, iteration 3" ); done_testing(); Tie-Cycle-1.19/t/pod.t000644 000765 000024 00000000206 12207160015 014662 0ustar00brianstaff000000 000000 use Test::More 0.95; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Tie-Cycle-1.19/t/pod_coverage.t000644 000765 000024 00000000357 12207160015 016544 0ustar00brianstaff000000 000000 use Test::More 0.95; eval "use Test::Pod::Coverage"; if( $@ ) { plan skip_all => "Test::Pod::Coverage required for testing POD"; } else { pod_coverage_ok( "Tie::Cycle", { trustme => [ qr/^[A-Z_]+$/ ] } ); } done_testing(); Tie-Cycle-1.19/t/test_manifest000644 000765 000024 00000000060 12207160015 016501 0ustar00brianstaff000000 000000 # $Id$ load.t pod.t pod_coverage.t cycle.t one.tTie-Cycle-1.19/lib/Tie/000755 000765 000024 00000000000 12207160017 014743 5ustar00brianstaff000000 000000 Tie-Cycle-1.19/lib/Tie/Cycle.pm000644 000765 000024 00000006230 12207160015 016337 0ustar00brianstaff000000 000000 package Tie::Cycle; use strict; our $VERSION = '1.19'; use Carp qw(carp); use constant CURSOR_COL => 0; use constant COUNT_COL => 1; use constant ITEM_COL => 2; sub TIESCALAR { my( $class, $list_ref ) = @_; my $self = bless [], $class; unless( $self->STORE( $list_ref ) ) { carp "The argument to Tie::Cycle must be an array reference"; return; } return $self; } sub FETCH { my( $self ) = @_; my $index = $self->[CURSOR_COL]++; $self->[CURSOR_COL] %= $self->_count; return $self->_item( $index ); } sub STORE { my( $self, $list_ref ) = @_; return unless ref $list_ref eq ref []; my @shallow_copy = map { $_ } @$list_ref; $self->[CURSOR_COL] = 0; $self->[COUNT_COL] = scalar @shallow_copy; $self->[ITEM_COL] = \@shallow_copy; } sub reset { $_[0]->[CURSOR_COL] = 0 } sub previous { my( $self ) = @_; my $index = $self->_cursor - 1; $self->[CURSOR_COL] %= $self->_count; return $self->_item( $index ); } sub next { my( $self ) = @_; my $index = $self->_cursor + 1; $self->[CURSOR_COL] %= $self->_count; return $self->_item( $index ); } sub _cursor { $_[0]->[CURSOR_COL] } sub _count { $_[0]->[COUNT_COL] } sub _item { $_[0]->[ITEM_COL][ $_[1] // $_[0]->_cursor ] } "Tie::Cycle"; __END__ =head1 NAME Tie::Cycle - Cycle through a list of values via a scalar. =head1 SYNOPSIS use v5.10.1; use Tie::Cycle; tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF 000000 FFFF00 ) ]; say $cycle; # FFFFFF say $cycle; # 000000 say $cycle; # FFFF00 say $cycle; # FFFFFF back to the beginning (tied $cycle)->reset; # back to the beginning =head1 DESCRIPTION You use C to go through a list over and over again. Once you get to the end of the list, you go back to the beginning. You don't have to worry about any of this since the magic of tie does that for you. The tie takes an array reference as its third argument. The tie should succeed unless the argument is not an array reference. Previous versions required you to use an array that had more than one element (what's the pointing of looping otherwise?), but I've removed that restriction since the number of elements you want to use may change depending on the situation. During the tie, this module makes a shallow copy of the array reference. If the array reference contains references, and those references are changed after the tie, the elements of the cycle will change as well. See the included F script for an example of this effect. =head1 OBJECT METHODS You can call methods on the underlying object (which you access with C ). =over 4 =item reset Roll the iterator back to the starting position. The next access will give the first element in the list. =item previous Give the previous element. This does not affect the current position. =item next Give the next element. This does not affect the current position. You can peek at the next element if you like. =back =head1 SOURCE AVAILABILITY This module is on Github: https://github.com/briandfoy/tie-cycle =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright 2000-2013, brian d foy, All rights reserved This software is available under the same terms as perl. Tie-Cycle-1.19/examples/README000644 000765 000024 00000000105 12207160015 016144 0ustar00brianstaff000000 000000 See the tests in the t/ directory for examples until I add some more.