Class-Data-Inheritable-0.08/0000755000076500007650000000000010746346453015633 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/Changes0000644000076500007650000000151510746346433017126 0ustar tonytony00000000000000 0.08 Sat Jan 26 00:34:11 NZDT 2008 - Fix 'perltooc' typo in Docs 0.07 Sat Jan 26 00:34:11 NZDT 2008 - Relicense as dual AL/GPL 0.06 Wed Sep 20 14:35:55 BST 2006 - Sync the japanese docs (as best as possible!) 0.05 Sat Aug 26 18:27:12 UTC 2006 - Use correct bug reporting address (Jonathan Rockway) 0.04 Sat Sep 24 12:36:56 UTC 2005 - Tony Bowden now maintainer - Document how to set value when creating data - Complete rewrite of tests 0.03 Tue Mar 11 18:30:01 GMT 2003 - Rearranged the docs a smidge. - Added Japanese docs from perldocjp (thanks Atsuhi Kato) - mk_classdata() is now explicitly only a class method - Added this change log. 0.02 Sat Apr 15 05:14:17 GMT 2000 * mk_classdata() now creates a private accessor alias. 0.01 Fri Apr 14 09:17:15 GMT 2000 * First cut. Class-Data-Inheritable-0.08/doc/0000755000076500007650000000000010746346453016400 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/doc/jp/0000755000076500007650000000000010746346453017011 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/doc/jp/Class-Data-Inheritable.pod0000644000076500007650000000734510504241653023652 0ustar tonytony00000000000000=pod =head1 名前 Class::Data::Inheritable - 継承可能な, オーバーライド可能な、クラスデータ =head1 概要 package Stuff; use base qw(Class::Data::Inheritable); # DataFileを、継承可能なクラスデータとしてセットアップする。 Stuff->mk_classdata('DataFile'); # このクラスためにデータファイルの場所を宣言する。 Stuff->DataFile('/etc/stuff/data'); Stuff->mk_classdata(DataFile => '/etc/stuff/data'); =head1 概要 Class::Data::Inheritable は、クラスデータのアクセサ/ミューテータを作るのに向いています。 つまり、(単一のオブジェクトとは違って、)クラス全体に何かを蓄えたい場合です。 このデータは、サブクラスで継承され得ますし、オーバーライドされ得ます。 例: Pere::Ubu->mk_classdata('Suitcase'); これは、Suitcate メソッドを、Pere::Ubu クラスに生成します。 新しいメソッドは、クラスデータの一つを得たり、セットするのに、使われ得ます。 Pere::Ubu->Suitcase('Red'); $suitcase = Pere::Ubu->Suitcase; 面白い部分が、クラスが Pere::Ubu から継承するときに起こります: package Raygun; use base qw(Pere::Ubu); # Raygunのスーツケースは Red. $suitcase = Raygun->Suitcase; Raygun は、Pere::Ubuからスーツケースクラスデータ継承します。 クラスデータの継承は、メソッド継承にanalgousを動かします。 Raygunが、継承されたクラスデータを(Suitcase()を使って、新しい値をセットすることによって)"オーバーライド"しないかぎり、 Pere::Ubu で、セットされたものをなんでも使い続け、以前の変更を継承し続けます。 # Raygun と Pere::Ubu の suitcases は、今は Blue です。 Pere::Ubu->Suitcase('Blue'); しかし、Raygun が、自分自身のSuitcase() をセットするべきだと決めると、 Suitcase() は、 今や、Pare::Ubu を"オーバーライド"しており、Raygun 自身のものです。 オーバーライドされたメソッドにちょうど、似ています。 # Raygun は orange のスーツケースを持つが、Pere::Ubu のスーツケースは、まだ Blue です. Raygun->Suitcase('Orange'); さて、Raygun は、Pare::Ubu をオーバーライドしたので、Pare::Ubu による、以前の変更は まったく Raygun には、影響を与えません。 # Raygun は、まだ、orange のスーツケースですが、 Pere::Ubu は、Samsonite を使います。 Pere::Ubu->Suitcase('Samsonite'); =head1 メソッド =head2 B Class->mk_classdata($data_accessor_name); Class->mk_classdata($data_accessor_name => $value); これはクラスメソッドで、新しいクラスデータのアクセサを宣言するのに使われます。 $data_accessor_name を名前に使って、新しいアクセサがクラス内に作られます。 オーバーライドを容易にするために、mk_classdata は、アクセサへのエイリアス _field_accessor() を作ります。 それで、Suitcase() には、_Suitcase_accessor() というエイリアスがあり、 このエイリアスは、Suitcase() と、ちょうど同じことをします。 単一のアクセサの振る舞いを変えようとして、 まだ、継承可能なクラスデータの恩恵を得たいなら、有益です。次の例のように。 sub Suitcase { my($self) = shift; warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid'; $self->_Suitcase_accessor(@_); } =head1 著作権 (原文まま) Copyright (c) 2000, Damian Conway and Michael G Schwern. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html) =head1 著者 (原文まま) Original code by Damian Conway. Maintained by Michael G Schwern until September 2005. Now maintained by Tony Bowden. =head1 BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-Data-Inheritable@rt.cpan.org =head1 SEE ALSO L は、とても入念なPerlのクラスデータについての議論があります。 =head1 翻訳について 翻訳者:加藤敦 (atusi@pure.ne.jp) Perlドキュメント日本語訳 Project にて、 Perlモジュール、ドキュメントの翻訳を行っております。 http://sourceforge.jp/projects/perldocjp/ http://freeml.com/ctrl/html/MLInfoForm/perldocjp@freeml.com http://www.perldoc.jp Class-Data-Inheritable-0.08/lib/0000755000076500007650000000000010746346453016401 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/lib/Class/0000755000076500007650000000000010746346453017446 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/lib/Class/Data/0000755000076500007650000000000010746346453020317 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/lib/Class/Data/Inheritable.pm0000644000076500007650000000774310746346444023116 0ustar tonytony00000000000000package Class::Data::Inheritable; use strict qw(vars subs); use vars qw($VERSION); $VERSION = '0.08'; sub mk_classdata { my ($declaredclass, $attribute, $data) = @_; if( ref $declaredclass ) { require Carp; Carp::croak("mk_classdata() is a class method, not an object method"); } my $accessor = sub { my $wantclass = ref($_[0]) || $_[0]; return $wantclass->mk_classdata($attribute)->(@_) if @_>1 && $wantclass ne $declaredclass; $data = $_[1] if @_>1; return $data; }; my $alias = "_${attribute}_accessor"; *{$declaredclass.'::'.$attribute} = $accessor; *{$declaredclass.'::'.$alias} = $accessor; } 1; __END__ =head1 NAME Class::Data::Inheritable - Inheritable, overridable class data =head1 SYNOPSIS package Stuff; use base qw(Class::Data::Inheritable); # Set up DataFile as inheritable class data. Stuff->mk_classdata('DataFile'); # Declare the location of the data file for this class. Stuff->DataFile('/etc/stuff/data'); # Or, all in one shot: Stuff->mk_classdata(DataFile => '/etc/stuff/data'); =head1 DESCRIPTION Class::Data::Inheritable is for creating accessor/mutators to class data. That is, if you want to store something about your class as a whole (instead of about a single object). This data is then inherited by your subclasses and can be overriden. For example: Pere::Ubu->mk_classdata('Suitcase'); will generate the method Suitcase() in the class Pere::Ubu. This new method can be used to get and set a piece of class data. Pere::Ubu->Suitcase('Red'); $suitcase = Pere::Ubu->Suitcase; The interesting part happens when a class inherits from Pere::Ubu: package Raygun; use base qw(Pere::Ubu); # Raygun's suitcase is Red. $suitcase = Raygun->Suitcase; Raygun inherits its Suitcase class data from Pere::Ubu. Inheritance of class data works analogous to method inheritance. As long as Raygun does not "override" its inherited class data (by using Suitcase() to set a new value) it will continue to use whatever is set in Pere::Ubu and inherit further changes: # Both Raygun's and Pere::Ubu's suitcases are now Blue Pere::Ubu->Suitcase('Blue'); However, should Raygun decide to set its own Suitcase() it has now "overridden" Pere::Ubu and is on its own, just like if it had overriden a method: # Raygun has an orange suitcase, Pere::Ubu's is still Blue. Raygun->Suitcase('Orange'); Now that Raygun has overridden Pere::Ubu futher changes by Pere::Ubu no longer effect Raygun. # Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite. Pere::Ubu->Suitcase('Samsonite'); =head1 Methods =head2 mk_classdata Class->mk_classdata($data_accessor_name); Class->mk_classdata($data_accessor_name => $value); This is a class method used to declare new class data accessors. A new accessor will be created in the Class using the name from $data_accessor_name, and optionally initially setting it to the given value. To facilitate overriding, mk_classdata creates an alias to the accessor, _field_accessor(). So Suitcase() would have an alias _Suitcase_accessor() that does the exact same thing as Suitcase(). This is useful if you want to alter the behavior of a single accessor yet still get the benefits of inheritable class data. For example. sub Suitcase { my($self) = shift; warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid'; $self->_Suitcase_accessor(@_); } =head1 AUTHOR Original code by Damian Conway. Maintained by Michael G Schwern until September 2005. Now maintained by Tony Bowden. =head1 BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-Data-Inheritable@rt.cpan.org =head1 COPYRIGHT and LICENSE Copyright (c) 2000-2005, Damian Conway and Michael G Schwern. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. =head1 SEE ALSO L has a very elaborate discussion of class data in Perl. Class-Data-Inheritable-0.08/Makefile.PL0000644000076500007650000000035510746344702017603 0ustar tonytony00000000000000use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Class::Data::Inheritable', VERSION_FROM => "lib/Class/Data/Inheritable.pm", ABSTRACT_FROM => "lib/Class/Data/Inheritable.pm", LICENSE => 'perl', PREREQ_PM => {}, ); Class-Data-Inheritable-0.08/MANIFEST0000644000076500007650000000027110315244127016747 0ustar tonytony00000000000000Changes doc/jp/Class-Data-Inheritable.pod lib/Class/Data/Inheritable.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml README t/Inheritable.t t/pod-coverage.t t/pod.t Class-Data-Inheritable-0.08/MANIFEST.SKIP0000644000076500007650000000054510315244121017512 0ustar tonytony00000000000000# Avoid version control files. \bRCS\b \bCVS\b ,v$ ,B$ ,D$ \B\.svn\b aegis.log$ \bconfig$ \bbuild$ # Avoid Makemaker generated and utility files. \bMakefile$ \bblib \bMakeMaker-\d \bpm_to_blib$ \bblibdirs$ # Avoid Module::Build generated and utility files. \bBuild$ \b_build # Avoid temp and backup files. ~$ \.gz$ \.old$ \.bak$ \.swp$ \.tdy$ \#$ \b\.# Class-Data-Inheritable-0.08/META.yml0000644000076500007650000000060010746346453017100 0ustar tonytony00000000000000--- #YAML:1.0 name: Class-Data-Inheritable version: 0.08 abstract: Inheritable, overridable class data license: perl author: ~ generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Class-Data-Inheritable-0.08/README0000644000076500007650000000671710746344735016527 0ustar tonytony00000000000000NAME Class::Data::Inheritable - Inheritable, overridable class data SYNOPSIS package Stuff; use base qw(Class::Data::Inheritable); # Set up DataFile as inheritable class data. Stuff->mk_classdata('DataFile'); # Declare the location of the data file for this class. Stuff->DataFile('/etc/stuff/data'); # Or, all in one shot: Stuff->mk_classdata(DataFile => '/etc/stuff/data'); DESCRIPTION Class::Data::Inheritable is for creating accessor/mutators to class data. That is, if you want to store something about your class as a whole (instead of about a single object). This data is then inherited by your subclasses and can be overriden. For example: Pere::Ubu->mk_classdata('Suitcase'); will generate the method Suitcase() in the class Pere::Ubu. This new method can be used to get and set a piece of class data. Pere::Ubu->Suitcase('Red'); $suitcase = Pere::Ubu->Suitcase; The interesting part happens when a class inherits from Pere::Ubu: package Raygun; use base qw(Pere::Ubu); # Raygun's suitcase is Red. $suitcase = Raygun->Suitcase; Raygun inherits its Suitcase class data from Pere::Ubu. Inheritance of class data works analogous to method inheritance. As long as Raygun does not "override" its inherited class data (by using Suitcase() to set a new value) it will continue to use whatever is set in Pere::Ubu and inherit further changes: # Both Raygun's and Pere::Ubu's suitcases are now Blue Pere::Ubu->Suitcase('Blue'); However, should Raygun decide to set its own Suitcase() it has now "overridden" Pere::Ubu and is on its own, just like if it had overriden a method: # Raygun has an orange suitcase, Pere::Ubu's is still Blue. Raygun->Suitcase('Orange'); Now that Raygun has overridden Pere::Ubu futher changes by Pere::Ubu no longer effect Raygun. # Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite. Pere::Ubu->Suitcase('Samsonite'); Methods mk_classdata Class->mk_classdata($data_accessor_name); Class->mk_classdata($data_accessor_name => $value); This is a class method used to declare new class data accessors. A new accessor will be created in the Class using the name from $data_accessor_name, and optionally initially setting it to the given value. To facilitate overriding, mk_classdata creates an alias to the accessor, _field_accessor(). So Suitcase() would have an alias _Suitcase_accessor() that does the exact same thing as Suitcase(). This is useful if you want to alter the behavior of a single accessor yet still get the benefits of inheritable class data. For example. sub Suitcase { my($self) = shift; warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid'; $self->_Suitcase_accessor(@_); } AUTHOR Original code by Damian Conway. Maintained by Michael G Schwern until September 2005. Now maintained by Tony Bowden. BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-Data-Inheritable@rt.cpan.org COPYRIGHT and LICENSE Copyright (c) 2000-2005, Damian Conway and Michael G Schwern. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. SEE ALSO perltootc has a very elaborate discussion of class data in Perl. Class-Data-Inheritable-0.08/t/0000755000076500007650000000000010746346453016076 5ustar tonytony00000000000000Class-Data-Inheritable-0.08/t/Inheritable.t0000644000076500007650000000250310315246000020464 0ustar tonytony00000000000000use strict; use Test::More tests => 15; package Ray; use base qw(Class::Data::Inheritable); Ray->mk_classdata('Ubu'); Ray->mk_classdata(DataFile => '/etc/stuff/data'); package Gun; use base qw(Ray); Gun->Ubu('Pere'); package Suitcase; use base qw(Gun); Suitcase->DataFile('/etc/otherstuff/data'); package main; foreach my $class (qw/Ray Gun Suitcase/) { can_ok $class => qw/mk_classdata Ubu _Ubu_accessor DataFile _DataFile_accessor/; } # Test that superclasses effect children. is +Gun->Ubu, 'Pere', 'Ubu in Gun'; is +Suitcase->Ubu, 'Pere', "Inherited into children"; is +Ray->Ubu, undef, "But not set in parent"; # Set value with data is +Ray->DataFile, '/etc/stuff/data', "Ray datafile"; is +Gun->DataFile, '/etc/stuff/data', "Inherited into gun"; is +Suitcase->DataFile, '/etc/otherstuff/data', "Different in suitcase"; # Now set the parent ok +Ray->DataFile('/tmp/stuff'), "Set data in parent"; is +Ray->DataFile, '/tmp/stuff', " - it sticks"; is +Gun->DataFile, '/tmp/stuff', "filters down to unchanged children"; is +Suitcase->DataFile, '/etc/otherstuff/data', "but not to changed"; my $obj = bless {}, 'Gun'; eval { $obj->mk_classdata('Ubu') }; ok $@ =~ /^mk_classdata\(\) is a class method, not an object method/, "Can't create classdata for an object"; is $obj->DataFile, "/tmp/stuff", "But objects can access the data"; Class-Data-Inheritable-0.08/t/pod-coverage.t0000644000076500007650000000024110315236726020624 0ustar tonytony00000000000000use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Class-Data-Inheritable-0.08/t/pod.t0000644000076500007650000000020110315236726017027 0ustar tonytony00000000000000use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();