| 1 | package Rose::ObjectX::CAF::MethodMaker; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use base qw( Rose::Object::MakeMethods::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | my $Debug = 0; #$ENV{PERL_DEBUG}; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Rose::ObjectX::CAF::MethodMaker - Class::Accessor::Fast compatability for Rose::Object | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # see Rose::ObjectX::CAF | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | This is a subclass of Rose::Object::MakeMethods::Generic. See those docs | ||||||||||||||||||||||||||||
| 21 | and those of Rose::ObjectX::CAF. | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head2 scalar | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Overrides the Rose::Object::MakeMethods::Generic method of the same name | ||||||||||||||||||||||||||||
| 28 | to provide read-only accessors like mk_ro_accessors(). | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # extend for mk_ro_accessors support | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | sub scalar { | ||||||||||||||||||||||||||
|
Subroutine
scalar: called CC=11 SCAR=33.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 2 | my ( $class, $name, $args ) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | my %methods; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | my $key = $args->{'hash_key'} || $name; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'hash_key'} || $name
MC/DC0%0/2
$args->{'hash_key'} || $name
$args->{'hash_key'}
$name
Truth table33%1/3
A || B
A= $args->{'hash_key'}B= $name
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | my $interface = $args->{'interface'} || 'get_set'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'interface'} || 'get_set'
MC/DC100%1/1
$args->{'interface'} || 'get_set'
$args->{'interface'}
Truth table100%2/2
A
A= $args->{'interface'}
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | if ( $interface eq 'get_set_init' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $init_method = $args->{'init_method'} || "init_$name"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{'init_method'} || "init_$name"
MC/DC0%0/1
$args->{'init_method'} || "init_$name"
$args->{'init_method'}
Truth table0%0/2
A
A= $args->{'init_method'}
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $methods{$name} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $_[0]->{$key} = $_[1] if ( @_ > 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | return defined $_[0]->{$key} | ||||||||||||||||||||||||||||
| 48 | ? $_[0]->{$key} | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | : ( $_[0]->{$key} = $_[0]->$init_method() ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | elsif ( $interface eq 'get_set' ) { | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | if ( $Rose::Object::MakeMethods::Generic::Have_CXSA | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
MC/DC0%0/2
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
$Rose::Object::MakeMethods::Generic::Have_CXSA
not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
Truth table33%1/3
A and not(B)
A= $Rose::Object::MakeMethods::Generic::Have_CXSAB= not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
| |||||||||||||||||||||||||||||
| 54 | && !$ENV{'ROSE_OBJECT_NO_CLASS_XSACCESOR'} ) | ||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | $methods{$name} = { | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | make_method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 58 | 1 | my ( $name, $target_class, $options ) = @_; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | $Debug | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | && warn | ||||||||||||||||||||||||||||
| 62 | "Class::XSAccessor make method ($name => $key) in $target_class\n"; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Class::XSAccessor->import( | ||||||||||||||||||||||||||||
| 65 | accessors => { $name => $key }, | ||||||||||||||||||||||||||||
| 66 | class => $target_class, | ||||||||||||||||||||||||||||
| 67 | 1 | ▶ | replace => $options->{'override_existing'} ? 1 : 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||||||||||
| 70 | 1 | }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $methods{$name} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $_[0]->{$key} = $_[1] if ( @_ > 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | return $_[0]->{$key}; | |||||||||||||||||||||||||||
| 76 | 0 | }; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | elsif ( $interface eq 'ro' ) { | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if ( $Rose::Object::MakeMethods::Generic::Have_CXSA | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
MC/DC0%0/2
$Rose::Object::MakeMethods::Generic::Have_CXSA and not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
$Rose::Object::MakeMethods::Generic::Have_CXSA
not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
Truth table33%1/3
A and not(B)
A= $Rose::Object::MakeMethods::Generic::Have_CXSAB= not $ENV{"ROSE_OBJECT_NO_CLASS_XSACCESOR"}
| |||||||||||||||||||||||||||||
| 81 | && !$ENV{'ROSE_OBJECT_NO_CLASS_XSACCESOR'} ) | ||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | $methods{$name} = { | ||||||||||||||||||||||||||||
| 84 | 1 | ▶ | make_method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 85 | 1 | my ( $name, $target_class, $options ) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | $Debug | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | && warn | ||||||||||||||||||||||||||||
| 89 | "Class::XSAccessor make method ($name => $key) in $target_class\n"; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Class::XSAccessor->import( | ||||||||||||||||||||||||||||
| 92 | getters => { $name => $key }, | ||||||||||||||||||||||||||||
| 93 | class => $target_class, | ||||||||||||||||||||||||||||
| 94 | 1 | ▶ | replace => $options->{'override_existing'} ? 1 : 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||
| 97 | 1 | }; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $methods{$name} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | croak "usage: $name() is read-only (getter not setter)"; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | return $_[0]->{$key}; | |||||||||||||||||||||||||||
| 105 | 0 | }; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | else { Carp::croak "Unknown interface: $interface" } | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | return \%methods; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Peter Karman, C<< <karman at cpan.org> >> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 BUGS | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Please report any bugs or feature requests to C<bug-rose-objectx-caf at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 120 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-ObjectX-CAF>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 121 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | perldoc Rose::ObjectX::CAF | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | You can also look for information at: | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-ObjectX-CAF> | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | L<http://annocpan.org/dist/Rose-ObjectX-CAF> | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | L<http://cpanratings.perl.org/d/Rose-ObjectX-CAF> | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | L<http://search.cpan.org/dist/Rose-ObjectX-CAF/> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Copyright 2009 Peter Karman. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 162 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 163 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 3 | 1; # End of Rose::ObjectX::CAF | |||||||||||||||||||||||||||