| 1 | package Class::Accessor::Children::Fast; | ||||||||||
| 2 | 4 | ▶ | use base qw( Class::Accessor::Fast ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | $VERSION = '0.02'; | |||||||||
| 6 | |||||||||||
| 7 | 6 | ▶ | sub mk_child_accessors { | ||||||||
|
Subroutine
mk_child_accessors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 8 | 6 | _mk_child_classes( mk_accessors => @_ ); | |||||||||
| 9 | } | ||||||||||
| 10 | 1 | ▶ | sub mk_child_ro_accessors { | ||||||||
|
Subroutine
mk_child_ro_accessors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 11 | 1 | _mk_child_classes( mk_ro_accessors => @_ ); | |||||||||
| 12 | } | ||||||||||
| 13 | 1 | ▶ | sub mk_child_wo_accessors { | ||||||||
|
Subroutine
mk_child_wo_accessors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | 1 | _mk_child_classes( mk_wo_accessors => @_ ); | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 8 | ▶ | sub _mk_child_classes { | ||||||||
|
Subroutine
_mk_child_classes: called CC=7 SCAR=19.5
| |||||||||||
| 18 | 8 | my $method = shift; | |||||||||
| 19 | 8 | my $base = shift; | |||||||||
| 20 | 8 | ▶ | Carp::croak 'Odd number arguments' if scalar @_ % 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 7 | ▶ | while ( scalar @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 9 | my $name = shift; | |||||||||
| 23 | 9 | my $list = shift; | |||||||||
| 24 | 9 | ▶ | Carp::croak 'Invalid child class name' if ref $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 8 | ▶ | $list = [ grep {$_ ne ''} split( /\s+/, $list )] unless ref $list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 8 | ▶ | my $child = ( $name ne '' ) ? $base.'::'.$name : $base; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 8 | ▶ | if ( ! $child->isa( __PACKAGE__ )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 4 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 3 | push( @{$child.'::ISA'}, __PACKAGE__ ); | |||||||||
| 30 | } | ||||||||||
| 31 | 8 | $child->$method( @$list ); | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | =head1 NAME | ||||||||||
| 36 | |||||||||||
| 37 | Class::Accessor::Children::Fast - Faster, child-class/accessor generation | ||||||||||
| 38 | |||||||||||
| 39 | =head1 SYNOPSIS | ||||||||||
| 40 | |||||||||||
| 41 | BEFORE (WITHOUT THIS) | ||||||||||
| 42 | |||||||||||
| 43 | package MyClass::Foo; | ||||||||||
| 44 | use base qw( Class:Accessor::Fast ); | ||||||||||
| 45 | __PACKAGE__->mk_ro_accessors(qw( jacob michael joshua ethan )); | ||||||||||
| 46 | |||||||||||
| 47 | package MyClass::Bar; | ||||||||||
| 48 | use base qw( Class:Accessor::Fast ); | ||||||||||
| 49 | __PACKAGE__->mk_ro_accessors(qw( emily emma madison isabella )); | ||||||||||
| 50 | |||||||||||
| 51 | package MyClass::Baz; | ||||||||||
| 52 | use base qw( Class:Accessor::Fast ); | ||||||||||
| 53 | __PACKAGE__->mk_ro_accessors(qw( haruka haruto miyu yuto )); | ||||||||||
| 54 | |||||||||||
| 55 | AFTER (WITH THIS) | ||||||||||
| 56 | |||||||||||
| 57 | package MyClass; | ||||||||||
| 58 | use base qw( Class::Accessor::Children::Fast ); | ||||||||||
| 59 | __PACKAGE__->mk_child_ro_accessors( | ||||||||||
| 60 | Foo => [qw( jacob michael joshua ethan )], | ||||||||||
| 61 | Bar => [qw( emily emma madison isabella )], | ||||||||||
| 62 | Baz => [qw( haruka haruto miyu yuto )], | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||
| 66 | |||||||||||
| 67 | This module automagically generates child classes | ||||||||||
| 68 | which have accessor/mutator methods. | ||||||||||
| 69 | |||||||||||
| 70 | This module inherits C<Class::Accessor::Fast> to make accessors. | ||||||||||
| 71 | |||||||||||
| 72 | =head1 METHODS | ||||||||||
| 73 | |||||||||||
| 74 | This module provides the following methods in addition to all methods | ||||||||||
| 75 | provided by C<Class::Accessor::Fast>. | ||||||||||
| 76 | |||||||||||
| 77 | =head2 mk_child_accessors | ||||||||||
| 78 | |||||||||||
| 79 | MyClass->mk_child_accessors( Foo => \@fields, ... ); | ||||||||||
| 80 | |||||||||||
| 81 | This generates a child class named C<MyClass::Foo> | ||||||||||
| 82 | which have accessor/mutator methods each named in C<\@fields>. | ||||||||||
| 83 | |||||||||||
| 84 | =head2 mk_child_ro_accessors | ||||||||||
| 85 | |||||||||||
| 86 | MyClass->mk_child_ro_accessors( Bar => \@fields, ... ); | ||||||||||
| 87 | |||||||||||
| 88 | This generates a child class named C<MyClass::Bar> | ||||||||||
| 89 | which have read-only accessors (ie. true accessors). | ||||||||||
| 90 | |||||||||||
| 91 | =head2 mk_child_wo_accessors | ||||||||||
| 92 | |||||||||||
| 93 | MyClass->mk_child_wo_accessors( Baz => \@fields, ... ); | ||||||||||
| 94 | |||||||||||
| 95 | This generates a child class named C<MyClass::Baz> | ||||||||||
| 96 | which have write-only accessor (ie. mutators). | ||||||||||
| 97 | |||||||||||
| 98 | =head1 SEE ALSO | ||||||||||
| 99 | |||||||||||
| 100 | L<Class::Accessor::Children> | ||||||||||
| 101 | |||||||||||
| 102 | L<Class::Accessor::Fast> | ||||||||||
| 103 | |||||||||||
| 104 | =head1 AUTHOR | ||||||||||
| 105 | |||||||||||
| 106 | Yusuke Kawasaki L<http://www.kawa.net/> | ||||||||||
| 107 | |||||||||||
| 108 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 109 | |||||||||||
| 110 | Copyright (c) 2007 Yusuke Kawasaki. All rights reserved. | ||||||||||
| 111 | This program is free software; you can redistribute it and/or | ||||||||||
| 112 | modify it under the same terms as Perl itself. | ||||||||||
| 113 | |||||||||||
| 114 | =cut | ||||||||||
| 115 | 4 | 1; | |||||||||