| 1 | package HTML::GUI::log::event; | ||
| 2 | |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use POSIX; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use HTML::GUI::widget; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | HTML::GUI::log::event - Create and control a event input for webapp | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | Version 0.01 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | our $VERSION = '0.01'; | ||
| 19 | |||
| 20 | our @ISA = qw(HTML::GUI::widget); | ||
| 21 | |||
| 22 | =head1 EVENT | ||
| 23 | |||
| 24 | The event module to log all errors/debug/information messages | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | |||
| 29 | =head1 PUBLIC METHODS | ||
| 30 | |||
| 31 | =pod | ||
| 32 | |||
| 33 | =head3 new | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub new($$$) | ||
| 38 | { | ||
| 39 | my($class,$params) = @_; | ||
| 40 | my $this = $class->SUPER::new($params); | ||
| 41 | #the basic logging infos | ||
| 42 | $this->{ 'time'} = time; | ||
| 43 | $this->{stack} = HTML::GUI::log::event::getCurrentStack(); | ||
| 44 | if (defined $params && $params->{source}){ | ||
| 45 | $this->{source} = $params->{source}; | ||
| 46 | } | ||
| 47 | |||
| 48 | bless($this, $class); | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | =pod | ||
| 53 | |||
| 54 | =head3 getCurrentStack | ||
| 55 | |||
| 56 | Description : | ||
| 57 | return a array of the current stack | ||
| 58 | |||
| 59 | =cut | ||
| 60 | sub getCurrentStack | ||
| 61 | { | ||
| 62 | my ($self) = @_; | ||
| 63 | my @stack =() ; | ||
| 64 | my $i=1; | ||
| 65 | my ($package, $filename, $line,$subroutine) ; | ||
| 66 | while ($i==1 || $filename){ | ||
| 67 | ($package, $filename, $line,$subroutine) = caller($i); | ||
| 68 | push @stack, { | ||
| 69 | 'package' => $package, | ||
| 70 | filename => $filename, | ||
| 71 | line => $line, | ||
| 72 | subroutine=> $subroutine, | ||
| 73 | } unless (!defined $filename); | ||
| 74 | $i++; | ||
| 75 | } | ||
| 76 | return \@stack; | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | =pod | ||
| 81 | |||
| 82 | =head3 getMessage | ||
| 83 | |||
| 84 | Description : | ||
| 85 | return the message corresponding for the current event | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | sub getMessage | ||
| 90 | { | ||
| 91 | my ($self)=@_; | ||
| 92 | return "no message for generic event"; | ||
| 93 | } | ||
| 94 | |||
| 95 | =pod | ||
| 96 | |||
| 97 | =head3 dump | ||
| 98 | |||
| 99 | Description : | ||
| 100 | return a human readable string of the current event | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | sub dump | ||
| 105 | { | ||
| 106 | my ($self)=@_; | ||
| 107 | if (!exists $self->{stack}){ | ||
| 108 | return "No stack found !!!\n"; | ||
| 109 | } | ||
| 110 | my $dumpString = ''; | ||
| 111 | $dumpString .= "[".$self->printTime($self->{time})."] : "; | ||
| 112 | $dumpString .= $self->getMessage()."\n"; | ||
| 113 | foreach my $frame (@{$self->{stack}}){ | ||
| 114 | $dumpString .= " ->".$frame->{subroutine}; | ||
| 115 | if ($frame->{filename} !~ /\.pm$/){ | ||
| 116 | $dumpString .= " in ".$frame->{filename}.":".$frame->{line}; | ||
| 117 | }else{ | ||
| 118 | $dumpString .= " line:".$frame->{line}; | ||
| 119 | } | ||
| 120 | $dumpString .= "\n"; | ||
| 121 | } | ||
| 122 | $dumpString .="\n"; | ||
| 123 | return $dumpString; | ||
| 124 | } | ||
| 125 | |||
| 126 | =pod | ||
| 127 | |||
| 128 | =head3 printTime | ||
| 129 | |||
| 130 | Parameters : | ||
| 131 | $time : string : a value returned by the function time | ||
| 132 | Description : | ||
| 133 | return a human readable string of the date $time | ||
| 134 | |||
| 135 | =cut | ||
| 136 | sub printTime($$) | ||
| 137 | { | ||
| 138 | my ($self,$time)=@_; | ||
| 139 | return strftime "%Y:%m:%d %H:%M:%S", localtime($time); | ||
| 140 | } | ||
| 141 | |||
| 142 | =head1 AUTHOR | ||
| 143 | |||
| 144 | Jean-Christian Hassler, C<< <jhassler at free.fr> >> | ||
| 145 | |||
| 146 | =head1 BUGS | ||
| 147 | |||
| 148 | Please report any bugs or feature requests to | ||
| 149 | C<bug-gui-libhtml-event at rt.cpan.org>, or through the web interface at | ||
| 150 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-GUI-widget>. | ||
| 151 | I will be notified, and then you'll automatically be notified of progress on | ||
| 152 | your bug as I make changes. | ||
| 153 | |||
| 154 | =head1 SUPPORT | ||
| 155 | |||
| 156 | You can find documentation for this module with the perldoc command. | ||
| 157 | |||
| 158 | perldoc HTML::GUI::widget | ||
| 159 | |||
| 160 | You can also look for information at: | ||
| 161 | |||
| 162 | =over 4 | ||
| 163 | |||
| 164 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 165 | |||
| 166 | L<http://annocpan.org/dist/HTML-GUI-widget> | ||
| 167 | |||
| 168 | =item * CPAN Ratings | ||
| 169 | |||
| 170 | L<http://cpanratings.perl.org/d/HTML-GUI-widget> | ||
| 171 | |||
| 172 | =item * RT: CPAN's request tracker | ||
| 173 | |||
| 174 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-GUI-widget> | ||
| 175 | |||
| 176 | =item * Search CPAN | ||
| 177 | |||
| 178 | L<http://search.cpan.org/dist/HTML-GUI-widget> | ||
| 179 | |||
| 180 | =back | ||
| 181 | |||
| 182 | =head1 ACKNOWLEDGEMENTS | ||
| 183 | |||
| 184 | =head1 COPYRIGHT & LICENSE | ||
| 185 | |||
| 186 | Copyright 2007 Jean-Christian Hassler, all rights reserved. | ||
| 187 | |||
| 188 | This program is free software; you can redistribute it and/or modify it | ||
| 189 | under the same terms as Perl itself. | ||
| 190 | |||
| 191 | =cut | ||
| 192 | |||
| 193 | 1; # End of HTML::GUI::event::event | ||