Acme-Damn

 view release on metacpan or  search on metacpan

Damn.pm  view on Meta::CPAN


=head1 DESCRIPTION

B<Acme::Damn> provides a single routine, B<damn()>, which takes a blessed
reference (a Perl object), and I<unblesses> it, to return the original
reference.


=head2 EXPORT

By default, B<Acme::Damn> exports the method B<damn()> into the current
namespace. Aliases for B<damn()> (see below) may be imported upon request.

=head2 Methods

=over 4

=item B<damn> I<object>

B<damn()> accepts a single blessed reference as its argument, and returns
that reference unblessed. If I<object> is not a blessed reference, then

Damn.xs  view on Meta::CPAN

bless( rv , ... )
  SV * rv;

  PROTOTYPE: $;$

  CODE:
    /*
    ** how many arguments do we have?
    **    - if we have two arguments, with the second being 'undef'
    **      then we call damn()
    **    - otherwise, we default to CORE::bless()
    */
    if ( items == 2 && ! SvOK( ST(1) ) )
      rv  = __damn(rv);
    else {
      HV          *stash;
      STRLEN       len;
      const char  *ptr;
      SV          *sv;

      /* have we been called as a two-argument bless? */

README  view on Meta::CPAN

    Acme::Damn uses XS to access the internals of Perl for it's magic, and
    therefore must be compiled to be installed. Also, for testing,
    Acme::Damn relies on Test::More and Test::Exception.

DESCRIPTION
    Acme::Damn provides a single routine, damn(), which takes a blessed
    reference (a Perl object), and *unblesses* it, to return the original
    reference.

  EXPORT
    By default, Acme::Damn exports the method damn() into the current
    namespace. Aliases for damn() (see below) may be imported upon request.

  Methods
    damn *object*
        damn() accepts a single blessed reference as its argument, and
        returns that reference unblessed. If *object* is not a blessed
        reference, then damn() will "die" with an error.

    bless *reference*
    bless *reference* [ , *package* ]

t/6bless.t  view on Meta::CPAN

use strict;
use Test::More tests => 113;
use Test::Exception;

# load Acme::Damn, importing the replacement 'bless'
use Acme::Damn qw( bless );

#
# make sure bless displays the appropriate behaviour
#   - if called with two arguments, with the second argument explicitly set
#     set to 'undef', then default to damn()
#   - otherwise fall back to CORE::bless()
#

# define some argument types for damn
my  @array	= ();
my  %hash   = ();
my  $scalar = 0;

# set the patterns for matching bless exceptions
my  $x      = qr/Can't bless non-reference value/;

t/6bless.t  view on Meta::CPAN

 lives_ok { bless sub {}          }      "bless() lives with code reference";
 lives_ok { bless qr/./           }      "bless() lives with regex reference";
 lives_ok { bless \*STDOUT        }      "bless() lives with glob reference";

# ensure we can't bless into a reference
throws_ok { bless [] , [] } qr/Attempt to bless into a reference/
        , "bless() throws correct error with reference argument";


# ensure bless() works with a named package
#   - if the package name is '' then we default to 'main'
my  %try    = ( ''         => 'main'
              , 'main'     => 'main'
              , 'foo'      => 'foo'
              , 'foo::bar' => 'foo::bar'
              );
my  @try    = ( \$scalar
              , []
              , {}
              , sub {}
              , qr/./



( run in 0.720 second using v1.01-cache-2.11-cpan-0a6323c29d9 )