DOM2/Element/Shape.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« DOM2/Element/Shape/Fill.pm ↑ Summary DOM2.pm »
1 package SVG::DOM2::Element::Shape;
2 1 ▶use base "XML::DOM2::Element";
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 SVG::DOM2::Element::Shape
7  
8 =head1 DESCRIPTION
9  
10 Shape module controls all shapes within an svg document.
11 * style - fill and stroke
12 * transforms - transform attribute handeling
13  
14 Also deals with parent group and svg base inheritance via reverse lookup,
15  
16 =cut
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶use SVG::DOM2::Attribute::Transform;
Subroutine BEGIN: called CC=1 SCAR=2.6
23 use SVG::DOM2::Attribute::Style;
24 use SVG::DOM2::Attribute::Colour;
25 use SVG::DOM2::Attribute::Metric;
26 use SVG::DOM2::Attribute::Opacity;
27  
28 sub new
29 {
30 my ($proto, $shape, %args) = @_;
31 my $self = $proto->SUPER::new($shape, %args);
32 return $self;
33 }
34  
35 sub _attribute_handle
36 {
37 my ($self, $name, %opts) = @_;
38 confess "Attribute must have a name $name" if not $opts{'name'};
39 return SVG::DOM2::Attribute::Transform->new(%opts) if $name eq 'transform';
40 return SVG::DOM2::Attribute::Style->new(%opts) if $name eq 'style';
41 return SVG::DOM2::Attribute::Colour->new(%opts)
42 if $name eq 'fill' or $name eq 'stroke';
43 return SVG::DOM2::Attribute::Metric->new(%opts) if $name eq 'stroke-width';
44 return SVG::DOM2::Attribute::Opacity->new(%opts)
45 if $name eq 'fill-opacity' or $name eq 'stroke-opacity';
46 return $self->SUPER::_attribute_handle($name, %opts);
47 }
48  
49 sub _has_attribute
50 {
51 my ($self, $name) = @_;
52 return 1 if($name eq 'transform');
53 return 1 if($name eq 'style');
54 return $self->SUPER::_has_attribute($name);
55 }
56  
57 =head1 METHODS
58  
59 transforms - a list of transforms for this shape
60  
61 =cut
62  
63 sub transforms
64 {
65 my ($self) = @_;
66 my @tr;
67 # warn "Getting transforms for ".$self->name."\n";
68 if($self->getAttribute('transform')) {
69 push @tr, $self->getAttribute('transform')->transforms;
70 }
71 return @tr;
72 }
73  
74 =head1 METHODS
75  
76 style - attribute for controling style
77  
78 =cut
79  
80 sub style
81 {
82 my ($self) = @_;
83 return $self->getAttribute( 'style' );
84 }
85  
86 sub _style
87 {
88 my ($self, $name, $attr, %p) = @_;
89 # warn "Getting $name / $attr / $default\n";
90 # See if the value is stored
91 if(not $self->{$name}) {
92 # Get the basic style attribute
93 my $attribute = $self->getAttribute($attr);
94 if(not defined($attribute)) {
95 # Check the style attribute for it
96 $attribute = $self->style->_style($attr) if $self->style;
97 # if(not defined($attribute) and not $p{'noparent'}) {
98 # Now we go after the parent nodes, traversal
99 # if($self->getParent) {
100 # if( $self->getParent->can('_style') ) {
101 # my $s = $self->getParent->style;
102 # my $p = $s->value if defined($s);
103 # $attribute = $self->getParent->_style($name, $attr, %p, nodefault => 1);
104 # }
105 # }
106 # }
107 }
108 if(not $attribute and not $p{'nodefault'}) {
109 $attribute = $self->_attribute_handle( $attr, name => $name, owner => $self );
110 }
111 # Store the value for later
112 $self->{$name} = $attribute;
113 }
114 return $self->{$name};
115 }
116  
117 sub has_font { 0 };
118  
119 return 1;
« DOM2/Element/Shape/Fill.pm ↑ Summary DOM2.pm »