Bit-Vector-Minimal-1.3/0000755000175200017520000000000010320461267013470 5ustar tonytonyBit-Vector-Minimal-1.3/t/0000755000175200017520000000000010320461267013733 5ustar tonytonyBit-Vector-Minimal-1.3/t/1.t0000644000175200017520000000141310305532642014256 0ustar tonytony# vim:ft=perl use Test::More tests => 10; use_ok("Bit::Vector::Minimal"); { my $vec = Bit::Vector::Minimal->new; isa_ok $vec => "Bit::Vector::Minimal"; $vec->set(2); is $vec->display(), "00000100", "pattern set correctly for default LE"; is $vec->get(2), 1, "Bit two set"; is $vec->get(3), 0, "Bit three not set"; } { my $vec = Bit::Vector::Minimal->new( size => 32, width => 2, endianness => "big" ); isa_ok $vec => "Bit::Vector::Minimal"; $vec->set(2, 0b10); is $vec->display(), "00001000000000000000000000000000", "pattern set correctly for BE"; } { for (19 .. 21) { my $vec = Bit::Vector::Minimal->new(size => $_); is $vec->display(), "000000000000000000000000", "pattern initialized correctly when size not divisible by 8"; } } Bit-Vector-Minimal-1.3/t/pod.t0000644000175200017520000000020110320460626014671 0ustar tonytonyuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Bit-Vector-Minimal-1.3/t/pod-coverage.t0000644000175200017520000000024110320460626016466 0ustar tonytonyuse Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Bit-Vector-Minimal-1.3/lib/0000755000175200017520000000000010320461267014236 5ustar tonytonyBit-Vector-Minimal-1.3/lib/Bit/0000755000175200017520000000000010320461267014754 5ustar tonytonyBit-Vector-Minimal-1.3/lib/Bit/Vector/0000755000175200017520000000000010320461267016216 5ustar tonytonyBit-Vector-Minimal-1.3/lib/Bit/Vector/Minimal.pm0000644000175200017520000000560010320461170020134 0ustar tonytonypackage Bit::Vector::Minimal; use 5.006; use strict; use warnings; use Carp; our $VERSION = '1.3'; =head1 NAME Bit::Vector::Minimal - Object-oriented wrapper around vec() =head1 SYNOPSIS use Bit::Vector::Minimal; my $vec = Bit::Vector->new(size => 8, width => 1, endianness => "little"); # These are the defaults $vec->set(1); # $vec's internal vector now looks like "00000010" $vec->get(3); # 0 =head1 DESCRIPTION This is a much simplified, lightweight version of L, and wraps Perl's (sometimes confusing) C function in an object-oriented abstraction. =head1 METHODS =head2 new Creates a new bit vector. By default, this creates a one-byte vector with 8 one-bit "slots", with bit zero on the right of the bit pattern. These settings can be changed by passing parameters to the constructor: C will alter the size in bits of the vector; C will alter the width of the slots. The module will die if C is not an integer divisor of C. C controls whether the zeroth place is on the right or the left of the bit vector. =cut sub new { my $class = shift; my $self = bless { width => 1, size => 8, endianness => "little", @_ }, $class; croak "Don't know what endianness $self->{endianness} is meant to be" unless $self->{endianness} =~ /^(little|big)$/i; croak "Width ought to be a power of two" if !$self->{width} or (($self->{width} - 1) & $self->{width}); my $slots = $self->{size} / $self->{width}; croak "Cowardly refusing to store $slots items in a vector" unless $slots == int($slots); my $num_bytes = $self->{size} % 8 ? (($self->{size} + (8 - $self->{size} % 8)) / 8) : ($self->{size} / 8); $self->{pattern} = "\0" x $num_bytes; return $self; } =head2 set(POS[, VALUE]) Sets the bit or slot at position C to value C or "all bits on" if C is not given. =cut sub set { my ($self, $pos, $value) = @_; $value = 2**$self->{width} - 1 unless defined $value; $pos = 1 + $self->{width} - $pos if $self->{endianness} eq "big"; vec($self->{pattern}, $pos, $self->{width}) = $value; } =head2 get(POS) Returns the bit or slot at position C. =cut sub get { my ($self, $pos) = @_; $pos = 1 + $self->{width} - $pos if $self->{endianness} eq "big"; return vec($self->{pattern}, $pos, $self->{width}); } =head2 display Display the vector. For debugging purposes. =cut sub display { my $self = shift; return join "", map sprintf("%08b", ord $_), split //, $self->{pattern}; } =head1 AUTHOR Current maintainer: Tony Bowden Original author: Simon Cozens =head1 BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Bit-Vector-Minimal@rt.cpan.org =head1 SEE ALSO L =head1 COPYRIGHT AND LICENSE Copyright 2003, 2004 by Kasei This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Bit-Vector-Minimal-1.3/README0000644000175200017520000000000010320461237014333 0ustar tonytonyBit-Vector-Minimal-1.3/Changes0000644000175200017520000000071510320461217014761 0ustar tonytonyRevision history for Perl extension Bit::Vector::Minimal. 1.3 Tue Oct 4 11:07:43 UTC 2005 - Minor minor tweaks - Document 'display' method 1.2 Thu Sep 1 07:57:25 UTC 2005 - Properly initialise pattern where size is not a multiple of 8 (Marvin Humphrey) 1.1 Sun Oct 10 09:04:02 UTC 2004 - Tony Bowden now maintainer 1.0 Tue Nov 4 16:09:08 2003 - original version; created by h2xs 1.22 with options -b 5.6.0 -AX -n Bit::Vector::Minimal Bit-Vector-Minimal-1.3/MANIFEST.SKIP0000444000175200017520000000054510320461252015362 0ustar tonytony# Avoid version control files. \bRCS\b \bCVS\b ,v$ ,B$ ,D$ \B\.svn\b aegis.log$ \bconfig$ \bbuild$ # Avoid Makemaker generated and utility files. \bMakefile$ \bblib \bMakeMaker-\d \bpm_to_blib$ \bblibdirs$ # Avoid Module::Build generated and utility files. \bBuild$ \b_build # Avoid temp and backup files. ~$ \.gz$ \.old$ \.bak$ \.swp$ \.tdy$ \#$ \b\.# Bit-Vector-Minimal-1.3/Makefile.PL0000644000175200017520000000040610132175540015437 0ustar tonytonyuse 5.006; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Bit::Vector::Minimal', VERSION_FROM => 'lib/Bit/Vector/Minimal.pm', ABSTRACT_FROM => 'lib/Bit/Vector/Minimal.pm', PREREQ_PM => {}, AUTHOR => 'Tony Bowden ', ); Bit-Vector-Minimal-1.3/META.yml0000644000175200017520000000047710320461267014751 0ustar tonytony# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Bit-Vector-Minimal version: 1.3 version_from: lib/Bit/Vector/Minimal.pm installdirs: site requires: distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 Bit-Vector-Minimal-1.3/MANIFEST0000644000175200017520000000023410320461254014614 0ustar tonytonyChanges lib/Bit/Vector/Minimal.pm Makefile.PL MANIFEST MANIFEST.SKIP META.yml Module meta-data (added by MakeMaker) README t/1.t t/pod-coverage.t t/pod.t