Christian Hansen > Class-Param-0.1 > Class::Param::Callback

Download:
Class-Param-0.1.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Class::Param::Callback - Param instance with callbacks

SYNOPSIS ^

    %store  = ();
    $param = Class::Param::Callback->new(
        get    => sub { return $store{ $_[1] }         },
        set    => sub { return $store{ $_[1] } = $_[2] },
        has    => sub { return exists $store{ $_[1] }  },
        names  => sub { return keys %store             },
        remove => sub { return delete $store{ $_[1] }  }
    );

DESCRIPTION ^

Construct a params instance using callbacks.

METHODS ^

new

This method takes a hash of parameters. The following options are valid:

get
    get => sub {
        my ( $self, $name ) = @_;
        return $hash{ $name };
    }

Required.

set
    set => sub {
        my ( $self, $name, $value ) = @_;
        return $hash{ $name } = $value;
    }

Required.

names
    names => sub {
        my ( $self ) = @_;
        return keys %hash;
    }

Required.

remove
    remove => sub {
        my ( $self, $name ) = @_;
        return delete $hash{ $name };
    }

Required.

clear
    clear => sub {
        my ( $self ) = @_;
        return %hash = ();
    }

Optional.

count
    count => sub {
        my ( $self ) = @_;
        return scalar keys %hash;
    }

Optional.

has
    has => sub {
        my ( $self, $name ) = @_;
        return exists $hash{ $name };
    }

Optional.

param
    param => sub { }

Optional. See Class::Param::Base for expected behavior.

add
    add => sub { }

Optional. See Class::Param::Base for expected behavior.

scan
    scan => sub { }

Optional. See Class::Param::Base for expected behavior.

as_hash
    param => sub { }

Optional. See Class::Param::Base for expected behavior.

SEE ASLO ^

Class::Param.

AUTHOR ^

Christian Hansen chansen@cpan.org

COPYRIGHT ^

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: