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
Badger::Mixin(3) User Contributed Perl Documentation Badger::Mixin(3)

Badger::Mixin - base class mixin object

The "Badger::Mixin" module is a base class for mixin modules. You can use the Badger::Class module to declare mixins:

    package Your::Mixin::Module;
    
    use Badger::Class
        mixins => '$FOO @BAR %BAZ bam';
        
    # some sample data/methods to mixin
    our $FOO = 'Some random text';
    our @BAR = qw( foo bar baz );
    our %BAZ = ( hello => 'world' );
    sub bam { 'just testing' };

Behind the scenes this adds "Badger::Mixin" as a base class of "Your::Mixin::Module" and calls the mixins method to declare what symbols can be mixed into another module. You can write this code manually if you prefer:

    package Your::Mixin::Module;
    
    use base 'Badger::Mixin';
    
    __PACKAGE__->mixins('$FOO @BAR %BAZ bam');
    
    # sample data/methods as before

The Badger::Mixin module is a base class for mixin modules. Mixins are modules that implement functionality that can be mixed into other modules. This allows you to create modules using composition instead of misuing inheritance.

The easiest way to define a mixin module is via the "Badger::Class" module.

    package Your::Mixin::Module;
    
    use Badger::Class
        mixins => '$FOO @BAR %BAZ bam';

This is syntactic sugar for the following code:

    package Your::Mixin::Module;
    
    use base 'Badger::Mixin';
    __PACKAGE__->mixins('$FOO @BAR %BAZ bam');

The mixin module declares what symbols it makes available for mixing using the mixins() (plural) method (either indirectly as in the first example, or directly as in the second).

The mixin() (singular) method can then be used to mix those symbols into another module. Badger::Class provides the mixin hook which you can use:

    package Your::Other::Module;
    
    use Badger::Class
        mixin => 'Your::Mixin::Module';

Or you can call the mixin() method manually if you prefer.

    package Your::Other::Module;
    
    use Your::Mixin::Module;
    Your::Mixin::Module->mixin(__PACKAGE__);

Mixins are little more than modules with a specialised export mechanism. In fact, the "Badger::Mixin" module uses the Badger::Exporter behind the scenes to export the mixin symbols into the target package. Mixins are intentionally simple. If you want to do anything more complicated in terms of exporting symbols then you should use the Badger::Exporter module directly instead.

This method is used to declare what symbols are available for mixing in to other packages. Symbols can be specified as a list of items, a reference to a list of items or as a single whitespace delimited string.

    package Your::Module;
    use base 'Badger::Mixin';
    
    # either list of symbols...
    __PACKAGE__->mixins('$FOO', '@BAR', '%BAZ', 'bam');
    
    # ...or reference to a list
    __PACKAGE__->mixins(['$FOO', '@BAR', '%BAZ', 'bam']);
    
    # ...or single string of whitespace delimited symbols
    __PACKAGE__->mixins('$FOO @BAR %BAZ bam');

This method is used to mixin the symbols declared via mixins() into the package specified by the $package argument.

    Your::Mixin::Module->mixin('My::Module');

Andy Wardley <http://wardley.org/>

Copyright (C) 2005-2009 Andy Wardley. All rights reserved.

Badger::Class
2016-12-12 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.