Attribute-TieClasses

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME
    Attribute::TieClasses - Attribute wrappers for CPAN Tie classes

VERSION
    version 1.101700

SYNOPSIS
      use Attribute::TieClasses;
      my $k : Timeout(EXPIRES => '+2s');
      # loads in Tie::Scalar::Timeout and tie()s $k with those options

DESCRIPTION
    Damian Conway's wonderful "Attribute::Handlers" module provides an easy
    way to use attributes for "tie()"ing variables. In effect, the code in
    the synopsis is simply

        use Attribute::Handlers
            autotie => { Timeout => 'Tie::Scalar::Timeout' };

    Still, going one step further, it might be useful to have centrally
    defined attributes corresponding to commonly used Tie classes found on
    CPAN.

    Simply "use()"ing this module doesn't bring in all those potential Tie
    classes; they are only loaded when an attribute is actually used.

    The following attributes are defined:

README  view on Meta::CPAN

      RegexpKeyed        HASH          Tie::RegexpHash
      Secure             HASH          Tie::SecureHash
      Sentient           HASH          Tie::SentientHash
      Shadow             HASH          Tie::ShadowHash
      Shadowed           HASH          Tie::ShadowHash
      Sort               HASH          Tie::SortHash
      Sorted             HASH          Tie::SortHash
      Strict             HASH          Tie::StrictHash
      Substr             HASH          Tie::SubstrHash
      TextDir            HASH          Tie::TextDir
      Timeout            SCALAR        Tie::Scalar::Timeout
      Toggle             SCALAR        Tie::Toggle
      Transact           HASH          Tie::TransactHash
      TwoLevel           HASH          Tie::TwoLevelHash
      Vec                ARRAY         Tie::VecArray
      Vector             ARRAY         Tie::VecArray
      WarnGlobal         SCALAR        Tie::WarnGlobal::Scalar

    I haven't had occasion to test all of these attributes; they were taken
    from the module descriptions on CPAN. For some modules where the name
    didn't ideally translate into an attribute name (e.g.,

README  view on Meta::CPAN


  make_tie_scalar
    Returns the code line for the tie of a hash variable that is needed by
    "make_handler()".

  make_tie_var
    Is more flexible than the other "make_tie_*()" functions in that it
    checks the type of the variable that the attribute is being applied to.

EXAMPLES
        # Tie::Scalar::Timeout
        my $m : Timeout(NUM_USES => 3, VALUE => 456, POLICY => 777);
        print "$m\n" for 1..5;

        # Tie::Hash::Rank
        my %scores : Ranked;
        %scores = (
            Adams   => 78,
            Davies  => 35,
            Edwards => 84,
            Thomas  => 47
        );

lib/Attribute/TieClasses.pm  view on Meta::CPAN

    Rank         => 'HASH=Tie::Hash::Rank',
    Ref          => 'HASH=Tie::RefHash',
    Regexp       => 'HASH=Tie::RegexpHash',
    Secure       => 'HASH=Tie::SecureHash',
    Sentient     => 'HASH=Tie::SentientHash',
    Shadow       => 'HASH=Tie::ShadowHash',
    Sort         => 'HASH=Tie::SortHash',
    Strict       => 'HASH=Tie::StrictHash',
    Substr       => 'HASH=Tie::SubstrHash',
    TextDir      => 'HASH=Tie::TextDir',
    Timeout      => 'SCALAR=Tie::Scalar::Timeout',
    Toggle       => 'SCALAR=Tie::Toggle',
    Transact     => 'HASH=Tie::TransactHash',
    TwoLevel     => 'HASH=Tie::TwoLevelHash',
    Vec          => 'ARRAY=Tie::VecArray',
    WarnGlobal   => 'SCALAR=Tie::WarnGlobal::Scalar',
);

# Define synonyms for each attribute. Each synonym creates another handler,
# so use them sparingly.
# Each hash value can be a string or a reference to an array of strings.

lib/Attribute/TieClasses.pm  view on Meta::CPAN


Attribute::TieClasses - Attribute wrappers for CPAN Tie classes

=head1 VERSION

version 1.101700

=head1 SYNOPSIS

  use Attribute::TieClasses;
  my $k : Timeout(EXPIRES => '+2s');
  # loads in Tie::Scalar::Timeout and tie()s $k with those options

=head1 DESCRIPTION

Damian Conway's wonderful C<Attribute::Handlers> module provides
an easy way to use attributes for C<tie()>ing variables. In effect,
the code in the synopsis is simply

    use Attribute::Handlers
        autotie => { Timeout => 'Tie::Scalar::Timeout' };

Still, going one step further, it might be useful to have centrally
defined attributes corresponding to commonly used Tie classes found
on CPAN.

Simply C<use()>ing this module doesn't bring in all those potential
Tie classes; they are only loaded when an attribute is actually
used.

The following attributes are defined:

lib/Attribute/TieClasses.pm  view on Meta::CPAN

  RegexpKeyed        HASH          Tie::RegexpHash
  Secure             HASH          Tie::SecureHash
  Sentient           HASH          Tie::SentientHash
  Shadow             HASH          Tie::ShadowHash
  Shadowed           HASH          Tie::ShadowHash
  Sort               HASH          Tie::SortHash
  Sorted             HASH          Tie::SortHash
  Strict             HASH          Tie::StrictHash
  Substr             HASH          Tie::SubstrHash
  TextDir            HASH          Tie::TextDir
  Timeout            SCALAR        Tie::Scalar::Timeout
  Toggle             SCALAR        Tie::Toggle
  Transact           HASH          Tie::TransactHash
  TwoLevel           HASH          Tie::TwoLevelHash
  Vec                ARRAY         Tie::VecArray
  Vector             ARRAY         Tie::VecArray
  WarnGlobal         SCALAR        Tie::WarnGlobal::Scalar

I haven't had occasion to test all of these attributes; they were
taken from the module descriptions on CPAN. For some modules where
the name didn't ideally translate into an attribute name (e.g.,

lib/Attribute/TieClasses.pm  view on Meta::CPAN

Returns the code line for the tie of a hash variable that is needed by
C<make_handler()>.

=head2 make_tie_var

Is more flexible than the other C<make_tie_*()> functions in that it checks the
type of the variable that the attribute is being applied to.

=head1 EXAMPLES

    # Tie::Scalar::Timeout
    my $m : Timeout(NUM_USES => 3, VALUE => 456, POLICY => 777);
    print "$m\n" for 1..5;

    # Tie::Hash::Rank
    my %scores : Ranked;
    %scores = (
        Adams   => 78,
        Davies  => 35,
        Edwards => 84,
        Thomas  => 47
    );



( run in 0.230 second using v1.01-cache-2.11-cpan-4d50c553e7e )