File Coverage

blib/lib/Gtk2/Ex/CellLayout/BuildAttributes.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
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 .
17              
18             package Gtk2::Ex::CellLayout::BuildAttributes;
19 1     1   902 use 5.008;
  1         5  
  1         46  
20 1     1   6 use strict;
  1         3  
  1         40  
21 1     1   17 use warnings;
  1         2  
  1         41  
22 1     1   749 use Gtk2;
  0            
  0            
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 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__