App/Chart/Gtk2/Ex/ToplevelSingleton.pm

filter: Statementstmt 52.2% 23 / 44 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 5 totaltotal 43.2% 32 / 74 CC 5 SCAR 10.0
CC
5
Cov
45%
__ANON__
6.0
instance_for_screen
6.0
new_instance
3.8
CRAP 2.7
« App/Chart/Suffix/KEX.pm ↑ Summary App/Chart/DownloadHandler/DividendsPage.pm »
1 # instance per-screen ?
2 # instance per-display and move to screen ?
3 #
4 # searching through list_toplevels picks up non-instance created windows
5 # too, maybe flag those created this way ...
6 #
7 # isa() in search might rightly or wrongly pick up subclasses
8  
9  
10 # Copyright 2009, 2010 Kevin Ryde
11  
12 # This file is part of Chart.
13 #
14 # Chart is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by the
16 # Free Software Foundation; either version 3, or (at your option) any later
17 # version.
18 #
19 # Chart is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # for more details.
23 #
24 # You should have received a copy of the GNU General Public License along
25 # with Chart. If not, see <http://www.gnu.org/licenses/>.
26  
27 package App::Chart::Gtk2::Ex::ToplevelSingleton;
28 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use App::Chart::Gtk2::Ex::ToplevelBits;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 # uncomment this to run the ### lines
35 #use Smart::Comments;
36  
37 1 ▶sub import {
Subroutine import: called CC=2 SCAR=7.6
38 1 my ($class, %options) = @_;
39 1 ▶ if (%options) {
Branch: 1 branch
BranchTrueFalseTotal
if (%options) 0 1 1
40 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 0 ${"${class}::_instance_options"} = \%options;
42 }
43 }
44  
45 # ClassName->has_instance ()
46 0 ▶sub has_instance {
Subroutine has_instance: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $class = shift;
48 0 return $class->has_instance_for_screen (undef, @_);
49 }
50 # ClassName->has_instance_for_screen ($screen)
51 0 ▶sub has_instance_for_screen {
Subroutine has_instance_for_screen: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my ($class, $screen) = @_;
53 0 $screen = App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen);
54  
55 # searching like this isn't fast, but it allows a toplevel to be moved to
56 # a different screen
57 0 ▶ return List::Util::first { ($_->isa($class) && $_->get_screen == $screen) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_->isa($class) and $_->get_screen == $screen 0 0 0
58 0 Gtk2::Window->list_toplevels;
59 }
60  
61 # ClassName->instance (args...)
62 0 ▶sub instance {
Subroutine instance: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $class = shift;
64 0 return $class->instance_for_screen (undef, @_);
65 }
66  
67 # ClassName->instance_for_screen ($screen, args...)
68 0 ▶sub instance_for_screen {
Subroutine instance_for_screen: not called CC=2 SCAR=17.9
Pod undocumented
69 0 my ($class, $screen) = (shift, shift);
70  
71 return $class->has_instance_for_screen($screen)
72 0 ▶ || do {
Condition0%0/3
$class->has_instance_for_screen($screen) || do { $class->new_instance('screen', App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen), @_) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->has_instance_for_screen($screen) || do { $class->new_instance('screen', App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen), @_) }
$class->has_instance_for_screen($screen) do { $class->new_instance('screen', App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen), @_) }
Truth table0%0/3
A || B
A= $class->has_instance_for_screen($screen)B= do { $class->new_instance('screen', App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen), @_) }
ABresult
1X1
011
000
73 ### ToplevelSingleton instance create
74 0 $class->new_instance (screen => App::Chart::Gtk2::Ex::ToplevelBits::_screen($screen),
75 @_);
76 };
77 }
78  
79 # default instance constructor
80 0 ▶sub new_instance {
Subroutine new_instance: not called CC=2 SCAR=13.4
Pod undocumented
81 0 my ($class) = @_;
82 0 my $self = Glib::Object::new (@_);
83 0 ▶ my $options = do { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
84 0 ${"${class}::_instance_options"} };
85 0 ▶ if ($options->{'hide_on_delete'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"hide_on_delete"}) 0 0 0
86 0 $self->signal_connect (delete_event => \&Gtk2::Widget::hide_on_delete);
87 }
88 0 return $self;
89 }
90  
91 1 1;
92 __END__
« App/Chart/Suffix/KEX.pm ↑ Summary App/Chart/DownloadHandler/DividendsPage.pm »