Class::Builtin - Scalar/Array/Hash as objects


Class-Builtin documentation Contained in the Class-Builtin distribution.

Index


Code Index:

NAME

Top

Class::Builtin - Scalar/Array/Hash as objects

VERSION

Top

$Id: Builtin.pm,v 0.5 2011/05/21 21:40:47 dankogai Exp $

SYNOPSIS

Top

Quick summary of what the module does.

Perhaps a little code snippet.

    use Class::Builtin;
    my $scalar = OO('perl');
    my $array  = OO([0..9]);
    my $hash   = OO({key=>'value'});

    print $scalar->length; # 4;
    print $array->length;  # 10;
    print $hash->keys->[0] # 'key'

EXPORT

Top

OO

FUNCTIONS

Top

See Class::Builtin::Scalar, Class::Builtin::Array, and Class::Builtin::Hash for details.

To check what methods the object has, simply try

  print $o->methods->join("\n");

AUTHOR

Top

Dan Kogai, <dankogai at dan.co.jp>

BUGS

Top

Please report any bugs or feature requests to bug-class-builtin at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Builtin. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Class::Builtin

You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Builtin

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Class-Builtin

* CPAN Ratings

http://cpanratings.perl.org/d/Class-Builtin

* Search CPAN

http://search.cpan.org/dist/Class-Builtin/

ACKNOWLEDGEMENTS

Top

autobox, overload, perlfunc http://www.ruby-lang.org/

COPYRIGHT & LICENSE

Top


Class-Builtin documentation Contained in the Class-Builtin distribution.

package Class::Builtin;
use 5.008001;
use warnings;
use strict;
our $VERSION = sprintf "%d.%02d", q$Revision: 0.5 $ =~ /(\d+)/g;

use Class::Builtin::Scalar ();
use Class::Builtin::Array ();
use Class::Builtin::Hash ();
use Data::Dumper ();
use Scalar::Util ();

require Exporter;
use base qw/Exporter/;

our @EXPORT = qw(OO);

our %new = (
    '' => __PACKAGE__ . '::Scalar',
    map { $_ => __PACKAGE__ . '::' . ucfirst( lc($_) ) } qw/ARRAY HASH/
  );

sub new {
    my $class = shift;
    my $obj   = shift;
    my $new   = $new{ ref $obj } or return $obj;
    $new->new($obj);
}

{
    # to make $a->sort happy
    if (my $pkg = caller){
	no strict 'refs';
	no warnings 'once';
	${$pkg . '::a'} = undef;
	${$pkg . '::b'} = undef;
	${$pkg . '::_'} = undef;
    }
}

sub OO { __PACKAGE__->new(@_) }

1; # End of Class::Builtin