Class-Builtin

 view release on metacpan or  search on metacpan

lib/Class/Builtin/Scalar.pm  view on Meta::CPAN

      : @_ == 2 ? CORE::substr $$self, $_[0], $_[1]
      : CORE::substr @$self, $_[0], $_[1], $_[2];
    return @_ > 2 ? $self : __PACKAGE__->new($ret);
}

sub split {
    my $self = shift;
    my $pat  = shift || qr//;
    my @ret  = CORE::split $pat, $$self;
    Class::Builtin::Array->new( [@ret] );
}

sub print {
    my $self = shift;
    @_ ? CORE::print {$_[0]} $$self : CORE::print $$self;
}

sub say {
    my $self = shift;
    local $\ = "\n";
    @_ ? CORE::print {$_[0]} $$self : CORE::print $$self;
}

sub methods {
    Class::Builtin::Array->new(
        [ sort grep { defined &{$_} } keys %Class::Builtin::Scalar:: ] );
}

# Encode-related
for my $meth (qw/decode encode decode_utf8/){
    eval qq{
    sub Class::Builtin::Scalar::$meth
    {
	my \$self = shift;
	my \$ret  = Encode::$meth(\$\$self,\@_);
	__PACKAGE__->new(\$ret);
    }
    };
    croak $@ if $@;
}
for my $meth (qw/encode_utf8/){
    eval qq{
    sub Class::Builtin::Scalar::$meth
    {
	my \$self = shift;
	my \$ret  = Encode::$meth(\$\$self);
	__PACKAGE__->new(\$ret);
    }
    };
    croak $@ if $@;
}

*bytes = \&encode_utf8;
*utf8  = \&decode_utf8;

# Scalar::Util
# dualvar() and  set_prototype() not included

our @scalar_util = qw(
  blessed isweak readonly refaddr reftype tainted
  weaken isvstring looks_like_number
);

for my $meth (qw/blessed isweak refaddr reftype weaken/){
    eval qq{
      sub Class::Builtin::Scalar::$meth
      {
	my \$self = shift;
	my \$ret  = Scalar::Util::$meth(\$self);
	__PACKAGE__->new(\$ret);
      }
    };
    croak $@ if $@;
}

for my $meth (qw/readonly tainted isvstring looks_like_number/){
    eval qq{
      sub Class::Builtin::Scalar::$meth
      {
	my \$self = shift;
	my \$ret  = Scalar::Util::$meth(\$\$self);
	__PACKAGE__->new(\$ret);
      }
    };
    croak $@ if $@;
}

1; # End of Class::Builtin::Scalar

=head1 NAME

Class::Builtin::Scalar - Scalar as an object

=head1 VERSION

$Id: Scalar.pm,v 0.3 2009/06/22 15:52:18 dankogai Exp $

=head1 SYNOPSIS

  use Class::Builtin::Scalar;                    # use Class::Builtin::Builtin;
  my $foo = Class::Builtin::Scalar->new('perl'); # OO('perl');
  print $foo->length; # 4

=head1 EXPORT

None.  But see L<Class::Builtin>

=head1 METHODS

This section is under construction. For the time being, try

  print Class::Builtin::Scalar->new(0)->methods->join("\n")

=head1 TODO

This section itself is to do :)

=over 2

=item * what should C<< $s->m(qr/.../) >> return ? SCALAR ? ARRAY ?

=item * more methods

=back



( run in 1.858 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )