Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Class::MethodMaker v2 syntax help requested
I've read about Class::MethodMaker in Damian Conway's 'Object Oriented
Perl'.  It uses v1 syntax.  The latest v2 documentation is extremely
minimal, not to mention full of typos.  I've googled everywhere looking
for v2 examples especially for -init and -default behavior examples,
but no luck.

Could a kind soul help me by converting Damian's v1 example to v2
syntax?  It follows below.
Thanks,
-Tom

package CD::Music;
$VERSION = 4.00;
use strict;

use Class::MethodMaker
new_with_init => 'new',
new_hash_init => '_init_args',
static_hash   => 'counter',
get_set       => [ qw( name artist publisher ISBN tracks rating room
shelf ) ] ;

sub count	{ $_[0]->counter('count') }
sub _incr_count	{ $_[0]->counter_tally('count') }
sub _decr_count	{ $_[0]->counter(count=>$_[0]->counter('count')-1) }

sub init
{
my ($self, %args) = @_;
$self->_init_args(%args);
$self->_incr_count();
return $self;
}

# destructor adjusts object count
sub DESTROY { $_[0]->_decr_count() }

# get or set room and shelf together
sub location
{
my ($self, $room, $shelf) = @_;
$self->room($room) if $room;
$self->shelf($shelf) if $shelf;
return ($self->room, $self->shelf)
}

package main;
# Create an object storing a CD's details
my $cd = CD::Music->new(
name      => "Piano Concerto 20",
artist    => "Mozart",
rating    => 10,
room      => 5,
shelf     => 1,
publisher => "Salieri Intl.",
ISBN      => "1426-43235624-2",
);


# What's the CD called?
print $cd->name, "\n";
print $cd->artist, "\n";
print $cd->rating, "\n";
print $cd->room, "\n";

# Where would we find it?
printf "Room %s, shelf %s\n", $cd->location;

# Move it to room 5, shelf 3
$cd->location(5,3);
printf "Room %s, shelf %s\n", $cd->location;

$cd->name("Tacobell Cannon");
$cd->tracks(1000);
print $cd->name, "\n";
print $cd->tracks, "\n";

print "There have been ", CD::Music->count(), " CDs created\n";


Report this thread to moderator Post Follow-up to this message
Old Post
tv
02-08-05 08:56 AM


Re: Class::MethodMaker v2 syntax help requested
quote:
Originally posted by tv I've read about Class::MethodMaker in Damian Conway's 'Object Oriented Perl'. It uses v 1 syntax. The latest v2 documentation is extremely minimal, not to mention full of typo s. I've googled everywhere looking for v2 examples especially for -init and -default be havior examples, but no luck.
I too have read Conway's book and plan to use MethodMaker forthwith And sear ching for the doc, I find the CPAN doc for ver 1.1, complete with the offeri ngs which Damian mentions; when I look at the latest v2 doc, not only is it sparse and obviously "in progress", but - it omits tons of functionality tha t is doc'd for v1, e.g. Classes/object-instances as types via the "object" s pecifier. Anyway - the scary thing is when briefly perusing the source code, v2 actual ly does seem to have dropped the aforementioned functionality - nothing in t here to handle an object specifier for example... all I can think is it is still work-in-progress and perhaps should not be available on CPAN yet... ?? ?s Please correct me if I'm wrong - perhaps CPAN docs are just out of date, inc luding the attached source? For now I just have to go with v1.1 if I can fi nd the rpm for the module.

Report this thread to moderator Post Follow-up to this message
Old Post
aprilia1k
02-20-05 11:49 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Modules archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.