GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Object::Role(3) User Contributed Perl Documentation Object::Role(3)

Object::Role - base class for non-Moose roles

 {
   package Object::Dumpable;
   use base qw/Object::Role/;
   use Data::Dumper;
   sub import
   {
     my ($class, @args) = @_;
     my ($caller, %args) = __PACKAGE__->parse_arguments(undef, @args);
     my $coderef = sub
       {
         my ($self) = @_;
         return Dumper($self);
       };
     __PACKAGE__->install_method(dump => $coderef, $caller);
   }
 }
 
 {
   package Foo;
   use Object::Dumpable;
   sub new { ... }
 }
 
 {
   package main;
   my $foo = Foo->new;
   warn $foo->dump;
 }

This will be better documented once I fully understand it myself!

The idea of this is to be a base class for roles like Object::DOES, Object::Stash and Object::ID. It handles parsing of import arguments, installing methods into the caller's namespace (like Exporter, but using a technique that is immune to namespace::autoclean) and tracking which packages have consumed your role.

While "Object::Role" is a base class for roles, it is not itself a role, so does not export anything. Instead, your role must inherit from it.

"parse_arguments($default_arg_name, @arguments)"
Will parse:

  package My::Class;
  use My::Role -foo => 1, -bar => [2,3], 4, 5;
    

as:

  (
    'My::Class',   # caller,
    (
      '-foo'             => [1],
      '-bar'             => [2, 3],
      $default_arg_name  => [4, 5],
    )
  )
    
"install_method($subname => $coderef, $package)"
Installs $coderef as "$package\::$subname".

Automatically calls register_consumer($package).

"register_consumer($package)"
Records that $package has consumed (used) your role.
"has_consumer($package)"
Check if $package has consumed (used) your role.

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Object-Role>.

Object::DOES, Object::AUTHORITY.

Toby Inkster <tobyink@cpan.org>.

This software is copyright (c) 2011 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2011-12-15 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.