Badger::Class

Class metaprogramming module
Download

Badger::Class Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Andy Wardley
  • Publisher web site:
  • http://search.cpan.org/~abw/

Badger::Class Tags


Badger::Class Description

Class metaprogramming module Badger::Class is a class metaprogramming Perl module.SYNOPSIS # composing a new module package Your::Module; use Badger::Class base => 'Badger::Base', # define base class(es) version => 1.00, # sets $VERSION debug => 0, # sets $DEBUG throws => 'wobbler', # sets $THROWS error type import => 'class', # import class() subroutine utils => 'blessed params',# imports from Badger::Utils codec => 'storable', # imports from Badger::Codecs codecs => 'base64 utf8' # codecs do encode/decode constants => 'TRUE FALSE', # imports from Badger::Constants constant => { # define your own constants pi => 3.14, e => 2.718, }, words => 'yes no quit', # define constant words accessors => 'foo bar', # create accessor methods mutators => 'wiz bang', # create mutator methods as_text => 'text', # auto-stringify via text() method is_true => 1, # overload boolean operator overload => { # overload other operators '>' => 'more_than', ' 'less_than', }, vars => { '$FOO' => 'Hello World', # defines $FOO package var '@BAR' => , # defines @BAR 'Z' => {x=>10, y=>20}, # defines Z # leading '$' is optional for scalar package vars WIZ => 'Hello World', # defines $WIZ as scalar value WAZ => , # defines $WAZ as list ref WOZ => {a=>10,y=>20}, # defines $WOZ as hash ref WUZ => sub { ... }, # defines $WUZ as code ref }, methods => { # create/bind methods wam => sub { ... }, bam => sub { ... }, }, exports => { # exports via Badger::Exporter all => '$X $Y wibble', # like @EXPORTS any => '$P $Q pi e', # like @EXPORT_OK tags => { # like %EXPORT_TAGS xy => '$X $Y', # NOTE: 'X Y Z' is syntactic pq => '$P $Q', # sugar for }, hooks => { # export hooks - this synopsis one => sub { ... }, # shows the various hooks that two => sub { ... }, # Badger::Class defines: base, }, # version, debug, etc. }, messages => { # define messages, e.g. for missing => 'Not found: %s', # errors, warnings, prompts, etc. have_u => 'Have you %s my %s?', volume => 'This %s goes up to %s', }; # Phew! # the rest of your module follows... our $X = 10; our $Y = 20; sub whatever { ... } # Other Badger::Class tricks use Badger::Class 'class'; # compose a new class on the fly class('Amplifier') ->base('Badger::Base') ->constant( max_volume => 10 ) ->methods( about => sub { "This amp goes up to " . shift->max_volume } ); Amplifier->about; # This amp goes up to 10 # when you need that push over the cliff... class('Nigels::Amplifier') ->base('Amplifier') ->constant( max_volume => 11 ); Nigels::Amplifier->about; # This amp goes up to 11Badger::Class is a class metaprogramming module. It provides methods for defining, extending and manipulating object classes and related metadata in a relatively clean and simple way.Using the Badger::Class module will automatically enable the strict and warnings pragmata in your module (thx Moose!). No exceptions. No questions asked. No answers given. It's for your own good. Requirements: · Perl


Badger::Class Related Software