BuildAttributes.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary Base.pm »
1 # Copyright 2007, 2008, 2009, 2010 Kevin Ryde
2  
3 # This file is part of Gtk2-Ex-CellLayout-Base.
4 #
5 # Gtk2-Ex-CellLayout-Base is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Gtk2-Ex-CellLayout-Base is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Gtk2-Ex-CellLayout-Base. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Gtk2::Ex::CellLayout::BuildAttributes;
19 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
23  
24 our $VERSION = 5;
25  
26 # set this to 1 for some diagnostic prints
27 use constant DEBUG => 0;
28  
29 sub new {
30 my ($class, %self) = @_;
31 return bless \%self, $class;
32 }
33  
34 sub START_ELEMENT {
35 my ($self, $context, $element_name, $attributes) = @_;
36  
37 if ($element_name eq 'attributes') {
38 # nothing to do in the intro bit
39  
40 } elsif ($element_name eq 'attribute') {
41 $self->{'attr_name'} = $attributes->{'name'};
42  
43 } else {
44 # this is a g_warning like GtkCellLayout attributes_start_element() uses,
45 # not sure if a "carp" would be more helpful
46 Glib->warning (undef, "Unsupported tag for Gtk2::Ex::CellLayout::Base \"$element_name\"\n");
47 }
48 }
49  
50 sub TEXT {
51 my ($self, $context, $text) = @_;
52 if ($self->{'attr_name'}) {
53 # add_attribute will complain for us if $text isn't a string of digits
54 if (DEBUG) { print $self->{'cell_layout'}," build add_attribute ",
55 $self->{'attr_name'},"=>",$text,"\n"; }
56 $self->{'cell_layout'}->add_attribute ($self->{'cell_renderer'},
57 $self->{'attr_name'}, $text);
58 $self->{'attr_name'} = undef;
59 }
60 }
61  
62 # This is called at each closing </attribute> etc. Don't need to do
63 # anything, but the Gtk2-Perl code in Gtk2::Buildable insists the method
64 # exists.
65 #
66 sub END_ELEMENT {
67 }
68  
69 1;
70 __END__
↑ Summary Base.pm »