| 1 | package Package::Prototype; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | our $VERSION = "0.02"; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use XSLoader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | XSLoader::load(__PACKAGE__, $VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=22 SCAR=30.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 19 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 19 | ▶ | die "create expects named options" if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 18 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 18 | for my $key (keys %options) { | |||||||||||||||||||||||||||||||||||||||||
| 16 | 21 | ▶ | die "Unknown create option: $key" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "properties" or $key eq "methods" or $key eq "classname"
$key eq "properties" or $key eq "methods"
MC/DC100%3/3
$key eq "properties" or $key eq "methods" or $key eq "classname"
$key eq "properties"
$key eq "methods"
$key eq "classname"
Truth table100%4/4
A or B or C
A= $key eq "properties"B= $key eq "methods"C= $key eq "classname"
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | unless $key eq 'properties' || $key eq 'methods' || $key eq 'classname'; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | ▶ | my $properties = exists $options{properties} ? $options{properties} : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | ▶ | my $methods = exists $options{methods} ? $options{methods} : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | ▶ | die "properties must be a hash reference" unless ref($properties) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | ▶ | die "methods must be a hash reference" unless ref($methods) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 16 | my %installed; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 32 | ▶ | my $install = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 32 | my ($name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 32 | ▶ | die "Method name must be a nonempty string" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $name or ref $name or not length $name
not defined $name or ref $name
MC/DC33%1/3
not defined $name or ref $name or not length $name
not defined $name
ref $name
not length $name
Truth table50%2/4
not(A) or B or not(C)
A= not defined $nameB= ref $nameC= not length $name
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | if !defined($name) || ref($name) || !length($name); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 31 | ▶ | die "Method name prototype is reserved by create" if $name eq 'prototype'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 30 | ▶ | die "Duplicate method name: $name" if exists $installed{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 28 | $installed{$name} = $code; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 16 | for my $name (sort keys %$methods) { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | die "Method $name must be a code reference" unless ref($methods->{$name}) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | $install->($name, $methods->{$name}); | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | for my $name (sort keys %$properties) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 21 | my $spec = $properties->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 21 | ▶ | die "Property $name must be a hash reference" unless ref($spec) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | for my $key (keys %$spec) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 32 | ▶ | die "Unknown property option: $key" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "value" or $key eq "reader" or $key eq "writer"
$key eq "value" or $key eq "reader"
MC/DC100%3/3
$key eq "value" or $key eq "reader" or $key eq "writer"
$key eq "value"
$key eq "reader"
$key eq "writer"
Truth table100%4/4
A or B or C
A= $key eq "value"B= $key eq "reader"C= $key eq "writer"
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | unless $key eq 'value' || $key eq 'reader' || $key eq 'writer'; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | ▶ | die "Property $name requires value" unless exists $spec->{value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | my $value = $spec->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 19 | ▶ | my $reader = exists $spec->{reader} ? $spec->{reader} : $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | ▶ | $install->($reader, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 19 | ▶ | die "Reader $reader expects no arguments" unless @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 18 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | ▶ | if (exists $spec->{writer}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | my $writer = $spec->{writer}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | ▶ | $install->($writer, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | die "Writer $writer expects one argument" unless @_ == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 8 | $value = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | }); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | my $obj = exists $options{classname} | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ? Package::Prototype::bless($class, {}, $options{classname}) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | : Package::Prototype::bless($class, {}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | $obj->prototype(%installed); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||||||||||