« blib/lib/Class/MakeMethods/Emulator/Inheritable.pm
↑ Summary
blib/lib/Class/MakeMethods/Attribute.pm »
| 1 | package Class::MakeMethods::Emulator::Struct; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 2 | ▶ | use Class::MakeMethods; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 2 | ▶ | use vars qw(@ISA @EXPORT); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 2 | require Exporter; | |||||||||||||
| 9 | 2 | push @ISA, qw(Exporter); | |||||||||||||
| 10 | 2 | @EXPORT = qw(struct); | |||||||||||||
| 11 | |||||||||||||||
| 12 | 5 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||
| 13 | 5 | my $self = shift; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 5 | ▶ | if ( @_ == 0 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 16 | 3 | $self->export_to_level( 1, $self, @EXPORT ); | |||||||||||||
| 17 | } elsif ( @_ == 1 ) { | ||||||||||||||
| 18 | 1 | $self->export_to_level( 1, $self, @_ ); | |||||||||||||
| 19 | } else { | ||||||||||||||
| 20 | 1 | &struct; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | ######################################################################## | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 2 | my %type_map = ( | |||||||||||||
| 27 | '$' => 'scalar', | ||||||||||||||
| 28 | '@' => 'array', | ||||||||||||||
| 29 | '%' => 'hash', | ||||||||||||||
| 30 | '_' => 'object', | ||||||||||||||
| 31 | ); | ||||||||||||||
| 32 | |||||||||||||||
| 33 | 4 | ▶ | sub struct { | ||||||||||||
|
Subroutine
struct: called CC=8 SCAR=22.4
Pod
undocumented
| |||||||||||||||
| 34 | 4 | my ($class, @decls); | |||||||||||||
| 35 | 4 | my $base_type = ref $_[1] ; | |||||||||||||
| 36 | 4 | ▶ | if ( $base_type eq 'HASH' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 37 | 2 | $base_type = 'Standard::Hash'; | |||||||||||||
| 38 | 2 | $class = shift; | |||||||||||||
| 39 | 2 | @decls = %{shift()}; | |||||||||||||
| 40 | 2 | ▶ | _usage_error() if @_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | } | ||||||||||||||
| 42 | elsif ( $base_type eq 'ARRAY' ) { | ||||||||||||||
| 43 | 0 | $base_type = 'Standard::Array'; | |||||||||||||
| 44 | 0 | $class = shift; | |||||||||||||
| 45 | 0 | @decls = @{shift()}; | |||||||||||||
| 46 | 0 | ▶ | _usage_error() if @_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | } | ||||||||||||||
| 48 | else { | ||||||||||||||
| 49 | 2 | $base_type = 'Standard::Array'; | |||||||||||||
| 50 | 2 | $class = (caller())[0]; | |||||||||||||
| 51 | 2 | @decls = @_; | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | 4 | ▶ | _usage_error() if @decls % 2 == 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | |||||||||||||||
| 55 | 4 | my @rewrite; | |||||||||||||
| 56 | 4 | ▶ | while ( scalar @decls ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 13 | my ($name, $type) = splice(@decls, 0, 2); | |||||||||||||
| 58 | push @rewrite, $type_map{$type} | ||||||||||||||
| 59 | ? ( $type_map{$type} => { 'name'=>$name, auto_init=>1 } ) | ||||||||||||||
| 60 | 13 | ▶ | : ( $type_map{'_'} => { 'name'=>$name, 'class'=>$type, auto_init=>1 } ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | } | ||||||||||||||
| 62 | Class::MakeMethods->make( | ||||||||||||||
| 63 | 4 | -TargetClass => $class, | |||||||||||||
| 64 | -MakerClass => $base_type, | ||||||||||||||
| 65 | "new" => 'new', | ||||||||||||||
| 66 | @rewrite | ||||||||||||||
| 67 | ); | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | sub _usage_error { | ||||||||||||
|
Subroutine
_usage_error: not called CC=1 SCAR=6.9
| |||||||||||||||
| 71 | 0 | require Carp; | |||||||||||||
| 72 | 0 | Carp::confess "struct usage error"; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | ######################################################################## | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 2 | 1; | |||||||||||||
| 78 | |||||||||||||||
| 79 | __END__ | ||||||||||||||