File Coverage

blib/lib/Rose/HTML/Object/Message.pm
Criterion Covered Total %
statement 61 75 81.3
branch 15 22 68.1
condition 5 8 62.5
subroutine 16 20 80.0
pod 2 7 28.5
total 99 132 75.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 44     44   1080  
  44         79  
  44         1060  
4             use Carp;
5 44     44   178 use Clone::PP;
  44         76  
  44         1879  
6 44     44   573 use Scalar::Util();
  44         885  
  44         266  
7 44     44   1492  
  44         85  
  44         871  
8             use Rose::HTML::Object::Messages qw(CUSTOM_MESSAGE);
9 44     44   247  
  44         83  
  44         275  
10             use base 'Rose::Object';
11 44     44   374  
  44         115  
  44         7412  
12             our $VERSION = '0.606';
13              
14             #our $Debug = 0;
15              
16             use overload
17             (
18             '""' => sub { shift->text },
19 0     0   0 'bool' => sub { 1 },
20 0     0   0 '0+' => sub { 1 },
21 0     0   0 fallback => 1,
22 44         432 );
23 44     44   1660  
  44         1048  
24             use Rose::Object::MakeMethods::Generic
25             (
26             scalar =>
27 44         476 [
28             'id',
29             'variant',
30             ],
31             );
32 44     44   4720  
  44         6104  
33              
34 44     44 0 24404 {
  44     12   1043  
  44         21338  
  12         41  
35             my($self) = shift;
36             @_ = (text => @_) if(@_ == 1);
37             $self->SUPER::init(@_);
38 856     856 1 35666 }
39 856 100       1873  
40 856         2069 {
41             my($self) = shift;
42              
43             if(@_)
44             {
45 2657     2657 0 7908 my %args;
46              
47 2657 100       4446 if(@_ == 1 && ref $_[0] eq 'ARRAY')
48             {
49 459         670 my $i = 1;
50             %args = (map { $i++ => $_ } @{$_[0]});
51 459 100 66     1913 }
    50 33        
52             elsif(@_ == 1 && ref $_[0] eq 'HASH')
53 400         550 {
54 400         508 %args = %{$_[0]};
  8         23  
  400         862  
55              
56             my $i = 1;
57              
58 59         107 foreach my $key (sort keys %args)
  59         230  
59             {
60 59         114 $args{$i} = $args{$key} unless(exists $args{$i});
61             $i++;
62 59         220 }
63             }
64 84 50       246 else
65 84         160 {
66             my $i = 1;
67             %args = map { $i++ => $_ } @_;
68             }
69              
70 0         0 $self->{'args'} = \%args;
71 0         0  
  0         0  
72             return wantarray ? %{$self->{'args'}} : $self->{'args'};
73             }
74 459         1343  
75             return wantarray ? %{$self->{'args'} || {}} : ($self->{'args'} ||= {});
76 459 50       1371 }
  0         0  
77              
78             {
79 2198 0 100     8260 my($self) = shift;
  0 50       0  
80             return Scalar::Util::weaken($self->{'parent'} = shift) if(@_);
81             return $self->{'parent'};
82             }
83              
84 8144     8144 0 12587 {
85 8144 100       15278 my($self) = shift;
86 6943         15263 my $clone = Clone::PP::clone($self);
87             $clone->parent(undef);
88             return $clone;
89             }
90              
91 0     0 0 0 {
92 0         0 my($self) = shift;
93 0         0  
94 0         0 if(@_)
95             {
96             if(UNIVERSAL::isa($_[0], __PACKAGE__))
97             {
98             $self->id($_[0]->id);
99 2245     2245 1 5966 return $self->{'text'} = $_[0]->text;
100             }
101 2245 100       3868  
102             $self->id(CUSTOM_MESSAGE);
103 396 50       1283 return $self->{'text'} = $_[0];
104             }
105 0         0  
106 0         0 return $self->{'text'};
107             }
108              
109 396         1200  
110 396         1828 1;
111              
112              
113 1849         9215 =head1 NAME
114              
115             Rose::HTML::Object::Message - Text message object.
116 44     44 0 298  
  44     2214   111  
  44         2366  
  2214         7606  
117             =head1 SYNOPSIS
118              
119             $msg = Rose::HTML::Object::Message->new('Hello world');
120             print $msg->text; # Hello world
121              
122             =head1 DESCRIPTION
123              
124             L<Rose::HTML::Object::Message> objects encapsulate a text message with an optional integer L<id|/id>.
125              
126             This class inherits from, and follows the conventions of, L<Rose::Object>. See the L<Rose::Object> documentation for more information.
127              
128             =head1 OVERLOADING
129              
130             Stringification is overloaded to call the L<text|/text> method. In numeric and boolean contexts, L<Rose::HTML::Object::Message> objects always evaluate to true.
131              
132             =head1 CONSTRUCTOR
133              
134             =over 4
135              
136             =item B<new [ PARAMS | TEXT ]>
137              
138             Constructs a new L<Rose::HTML::Object::Message> object. If a single argument is passed, it is taken as the value for the L<text|/text> parameter. Otherwise, PARAMS name/value pairs are expected. Any object method is a valid parameter name.
139              
140             =back
141              
142             =head1 OBJECT METHODS
143              
144             =over 4
145              
146             =item B<id [INT]>
147              
148             Get or set the message's integer identifier.
149              
150             =item B<text [ TEXT | OBJECT ]>
151              
152             Get or set the message's text. If the message text is set to a TEXT string (rather than a L<Rose::HTML::Object::Message>-derived OBJECT), the L<id|/id> is set to the value of the constant C<Rose::HTML::Object::Message::CUSTOM_MESSAGE>.
153              
154             =back
155              
156             =head1 AUTHOR
157              
158             John C. Siracusa (siracusa@gmail.com)
159              
160             =head1 LICENSE
161              
162             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.