Params::Flex - Write and Call methods in your style.


NAME

Params::Flex - Write and Call methods in your style.


SYNOPSIS

  package Some::Module;
  use Params::Flex;

  # constructor
  sub new { bless {},shift };

  sub hoge {
        my ($self, $arg1, $arg2) = args(@_);

        # You can call other functions with $self.
        # Moreover, you can use $self as hash reference even 
        # this function was called in non object-oriented style.
        if($self->{_cache}){
                $rv = $self->{_cache}; # use cache
        }
        else{
                $rv = $self->other_function($arg1, $arg2);
                $self->{_cache} = $rv; # store cache
        }

        return $rv;
  }

  # in your script

  use Some::Module;

  my $obj = new Some::Module;
  print $obj->hoge('foo', 'bar'); # ok

  print Some::Module::hoge('foo', 'bar'); # ok
  # same as 
  print Some::Module->hoge('foo', 'bar'); # ok


DESCRIPTION

There's more than one way to do it!

There are object oriented style and procedural style in this world. But if you are using Params::Flex, you can write methods in your favorite style and users can call it in their favorite style.

EXPORT

Function ``args'' was imported by default. If you don't want to import it, write as below:

 use Params::Flex();

and in function write as below:

  sub hoge {
        my ($self, $arg1, $arg2) = Params::Flex::args(@_);
        ...
  }

Instead of writing ``Params::Flex::args(@_)'', you can write ``Params::Flex::a(@_)''. I don't like to write many chars. This is why I named this module not ``Params::Argument'' but ``Params::Flex''.


FUNCTIONS

args()


  my ($self, $arg1, $arg2) = args(@_);
  # or 
  my ($self, @args) = args(@_);

Adjust function arguments.
Always function receives blessed hash reference ($self) as first argument.
Params::Flex creates and supplies it if first argument is not $self.
Auto-created $self is cached so three calling styles as below are equal.
They share same $self.
  Some::Module::func('foo', 'bar');
  Some::Module->func('foo', 'bar');
  func('foo', 'bar'); # if func() was imported.

Of course, $self will be different if function was called in object oriented style.

  $obj1->func('foo', 'bar');
  $obj2->func('foo', 'bar');

Notice that auto-created $self is not initialized. It is created as an empty blessed hash reference.

a()

Alias of ``args''.


SEE ALSO


TO DO

I will make option which create object ( do ``new Some::Module'' ) and set it in auto-created $self instead empty hash reference.


AUTHOR

Kagurazaka Mahito , < mahito@cpan.org >


COPYRIGHT AND LICENSE

Copyright (C) 2005 by Kagurazaka Mahito

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.

 Params::Flex - Write and Call methods in your style.