Re: [Catalyst] TT VMethods

2007-09-13 Thread Felix Antonius Wilhelm Ostmann

i use another easy way:

package C::V::TT;

use strict;
use base 'Catalyst::View::TT';

__PACKAGE__-config(
   {
   CATALYST_VAR = 'catalyst',
   ...
   FILTERS = {
   'dollar' = sub { sprintf('%.2f',$_[0]); },
   }
   },
);



so you can use it in the Template like this:

[% var | dollar %]

and you can chain that!

[% var | dollar | html | uri %]


(i hope that works, dont check that, just copy  paste from one app, 
perhaps typo or something small errors)



Mitchell Jackson schrieb:
Today I saw how easy it is to extend Template-Toolkit within 
Catalyst.  Perhaps somebody here will find this useful.


I wanted to easily format dollar amounts from within the tt2 
template.  I had been doing this with [% FILTER format( %.2f ) %], 
but having FILTER/END everywhere seemed a bit annoying, and I wanted 
to add commas to make the data easier to read on large numbers.


In Catalyst, you can add extensions to Template from your app's lib 
directory.  You can add filters ( Template::Plugin::Filter ) and 
VMethods ( Template::Plugin::VMethods ) simply by putting them into 
MyApp/lib/Template/Plugin


Following is an example that adds a 'commify' method to any scalar 
template variable.  [% var.commify %] to add seperating commas, [% 
var.commify(2) %] to add commas and round to two decimal places


/Mitch
OnSite Mobile



#MyApp/lib/Template/Plugin/commify.pm
package Template::Plugin::commify;

use Template::Plugin::VMethods;
use base qw(Template::Plugin::VMethods);
@SCALAR_OPS = qw(commify);

=head1 commify

   VMethod extension to format a number with pretty commas each 3rd 
digit,

   and to specify decimal precision

   Template Syntax:
   [% USE commify %]
   [% test = '1234567890.983457' %]
   [% test.commify%] 1,234,567,890.983457
   [% test.commify(2) %] 1,234,567,890.98

=cut

sub commify {
   my ( $data, $precision ) = @_;
   my $decimals;

   # don't do anything to the data if it doesn't look like a number
   return $data
   if $data !~ /^\d+(?:\.\d+)$/;

   # round to the specified precision
   $data = sprintf %.${precision}f, $data
   if defined $precision;

   # detach the decimals, we don't want commas there
   $decimals = $1 if $data =~ s/(\.\d+)//;

   # insert commas
   $data =~ s/(\d{1,3})(?=(?:\d\d\d)+(?!\d))/$1,/g;

   # reattach decimals
   $data .= $decimals if defined $decimals;

   $data;
}

1;



___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/





--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] (en) error screen translations

2007-08-31 Thread Felix Antonius Wilhelm Ostmann

Why de and at dont use the correct spelling?

(de) Bitte versuchen sie es später nocheinmal
(at) Konnten's bitt'schön später nochmal reinschauen

Ronald J Kimball schrieb:

Jonathan Rockway wrote:

Here's the list:

(en) Please come back later
(fr) SVP veuillez revenir plus tard
(de) Bitte versuchen sie es spaeter nocheinmal
(at) Konnten's bitt'schoen spaeter nochmal reinschauen
(no) Vennligst prov igjen senere
(dk) Venligst prov igen senere
(pl) Prosze sprobowac pozniej
(pt) Por favor, volte mais tarde
(ja) 後ほどお越しください
(el) Παρακαλούμε ξαναελάτε αργότερα.
(ro) Vă rugăm să reveniţi mai târziu.
(he) אנא שובו במועד מאוחר יותר
(cn) 请稍后再来
(lb) Kommt w.e.g. spéider nach eng Kéier zeréck.
(bg) Моля, опитайте след малко
(bø) børk børk børk!


Anything else?  The thought has occurred to me that we should order
these by popularity.


Needs a Spanish translation.

Ronald

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/





--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] (en) error screen translations

2007-08-31 Thread Felix Antonius Wilhelm Ostmann

uh, i was too fast ... the are another faults in the text *g*

(de) Bitte versuchen sie es später noch einmal

Felix Antonius Wilhelm Ostmann schrieb:

Why de and at dont use the correct spelling?

(de) Bitte versuchen sie es später nocheinmal
(at) Konnten's bitt'schön später nochmal reinschauen

Ronald J Kimball schrieb:

Jonathan Rockway wrote:

Here's the list:

(en) Please come back later
(fr) SVP veuillez revenir plus tard
(de) Bitte versuchen sie es spaeter nocheinmal
(at) Konnten's bitt'schoen spaeter nochmal reinschauen
(no) Vennligst prov igjen senere
(dk) Venligst prov igen senere
(pl) Prosze sprobowac pozniej
(pt) Por favor, volte mais tarde
(ja) 後ほどお越しください
(el) Παρακαλούμε ξαναελάτε αργότερα.
(ro) Vă rugăm să reveniţi mai târziu.
(he) אנא שובו במועד מאוחר יותר
(cn) 请稍后再来
(lb) Kommt w.e.g. spéider nach eng Kéier zeréck.
(bg) Моля, опитайте след малко
(bø) børk børk børk!


Anything else?  The thought has occurred to me that we should order
these by popularity.


Needs a Spanish translation.

Ronald

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/








--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Attribute::Handlers wont work in own classes under catalyst

2007-08-30 Thread Felix Antonius Wilhelm Ostmann

Nilson Santos Figueiredo Junior schrieb:

On 8/29/07, Felix Antonius Wilhelm Ostmann [EMAIL PROTECTED] wrote:
  

after a few tests we gone use this classes under catalyst ... and ...
dont work :-/ under catalyst our classes dont use Attribute::Handlers
:-/ we declare UNIVERSAL::Property and then use sub nondigit : Property
{ defined  !m{[0-9]} } (see the code)



Catalyst breaks regular subroutine attributes. Apparently, it tries to
parse them all so other code never gets the chance to parse them. I've
seen this problem before while using a module (which used subroutine
attributes) along with Catalyst and I decided to work around it
instead of looking for a proper fix.

Good luck. Hopefully someone else can come up with solution other than
using Catalyst's own attribute handling framework.
  


uh, that is hard stuff! We use this kind of attributes, cause we use the 
object also without catalyst (cronjobs etc) ... so i cant use the 
catalyst-stuff :-/


have you make a bugreport? how you is your work around?

thanks!




-Nilson Santos F. Jr.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


  



--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Attribute::Handlers wont work in own classes under catalyst

2007-08-30 Thread Felix Antonius Wilhelm Ostmann
i found this bug ... Attribute::Handles has a CHECK {} block ... and 
under catalyst this block wont be executed ... but Attribute::Handlers 
need that ... what is to do?


Felix Antonius Wilhelm Ostmann schrieb:

Nilson Santos Figueiredo Junior schrieb:

On 8/29/07, Felix Antonius Wilhelm Ostmann [EMAIL PROTECTED] wrote:
 

after a few tests we gone use this classes under catalyst ... and ...
dont work :-/ under catalyst our classes dont use Attribute::Handlers
:-/ we declare UNIVERSAL::Property and then use sub nondigit : 
Property

{ defined  !m{[0-9]} } (see the code)



Catalyst breaks regular subroutine attributes. Apparently, it tries to
parse them all so other code never gets the chance to parse them. I've
seen this problem before while using a module (which used subroutine
attributes) along with Catalyst and I decided to work around it
instead of looking for a proper fix.

Good luck. Hopefully someone else can come up with solution other than
using Catalyst's own attribute handling framework.
  


uh, that is hard stuff! We use this kind of attributes, cause we use 
the object also without catalyst (cronjobs etc) ... so i cant use the 
catalyst-stuff :-/


have you make a bugreport? how you is your work around?

thanks!




-Nilson Santos F. Jr.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/


  






--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Attribute::Handlers wont work in own classes under catalyst

2007-08-30 Thread Felix Antonius Wilhelm Ostmann

workaround:

the skript: xyz_server.pl make a 'require xyz;' changing this to 'use 
xyz'; will couse in working code :)


just 5 hours worktime for this :-/

why there is a 'require xyz' and not 'use xyz'? what other new bugs i 
produce with my hack? :)

the xzy_fastcgi.pl have the right 'use xyz' in it ...


Felix Antonius Wilhelm Ostmann schrieb:
i found this bug ... Attribute::Handles has a CHECK {} block ... and 
under catalyst this block wont be executed ... but Attribute::Handlers 
need that ... what is to do?


Felix Antonius Wilhelm Ostmann schrieb:

Nilson Santos Figueiredo Junior schrieb:

On 8/29/07, Felix Antonius Wilhelm Ostmann [EMAIL PROTECTED] wrote:
 

after a few tests we gone use this classes under catalyst ... and ...
dont work :-/ under catalyst our classes dont use Attribute::Handlers
:-/ we declare UNIVERSAL::Property and then use sub nondigit : 
Property

{ defined  !m{[0-9]} } (see the code)



Catalyst breaks regular subroutine attributes. Apparently, it tries to
parse them all so other code never gets the chance to parse them. I've
seen this problem before while using a module (which used subroutine
attributes) along with Catalyst and I decided to work around it
instead of looking for a proper fix.

Good luck. Hopefully someone else can come up with solution other than
using Catalyst's own attribute handling framework.
  


uh, that is hard stuff! We use this kind of attributes, cause we use 
the object also without catalyst (cronjobs etc) ... so i cant use the 
catalyst-stuff :-/


have you make a bugreport? how you is your work around?

thanks!




-Nilson Santos F. Jr.

___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: 
http://www.mail-archive.com/catalyst@lists.rawmode.org/

Dev site: http://dev.catalyst.perl.org/


  









--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--
Websuche   Search   Technology   GmbH  Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:+49 541 40666-22
Email: [EMAIL PROTECTED] - Website: www.websuche.de
--
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin: Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--


___
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Attribute::Handlers wont work in own classes under catalyst

2007-08-29 Thread Felix Antonius Wilhelm Ostmann

OK, first the problem:

we have build some classes with Attribute::Handlers (was inspired from 
Attribute::Property)


This works realy fine!

after a few tests we gone use this classes under catalyst ... and ... 
dont work :-/ under catalyst our classes dont use Attribute::Handlers 
:-/ we declare UNIVERSAL::Property and then use sub nondigit : Property 
{ defined  !m{[0-9]} } (see the code)


then you can call: $obj-nondigit(4) and it will croak or 
$obj-nondigit(car) and it will set the object-property nondigit to car.


under catalyst he ignore the redefined sub in UNIVERSAL::Property ... 
no, he dont call UNIVERSAL::Property to redefine sub :-/



MfG
Felix Ostmann



OK, here the code, you can test it with (works):
perl -d -MData::Dumper -MmyExample -e 'my $e = myExample-create(); 
$e-nondigit(car); print Dumper($e);'

or
perl -d -MData::Dumper -MmyExample -e 'my $e = myExample-create(); 
$e-nondigit(4); print Dumper($e);'



under catalyst (wont work):
sub default : Private {
my ($self, $c) = @_;
use myExample;
use Data::Dumper;
my $e = myExample-create();
$e-nondigit(car);
$c-response-body( Dumper($e) );
}



CODE:

package myExample;

use strict;
use warnings;

use 5.006;
use Attribute::Handlers;
use Carp qw/carp croak/;

$Carp::Internal{q/Attribute::Handlers/}++;  # may we be forgiven for our 
sins

$Carp::Internal{+__PACKAGE__}++;

sub UNIVERSAL::Property : ATTR(CODE) {
   my (undef, $self_glob, $check_code) = @_;

   ref($self_glob)
   or croak Cannot use property attribute with anonymous sub;

   my $property = *$self_glob{NAME};

   defined($self_glob)
   or undef $check_code;

   no warnings 'redefine';

   *$self_glob = sub {
   (my $self, local $_) = @_;

   if( @_ == 1 ) {
   exists($self-{_property}-{_current}-{$property})
   or croak Property $property not loaded;

   return $self-{_property}-{_current}-{$property};
   }

   if( @_ == 2 ) {
   ref($_)
   and croak Invalid value for $property property, no refs;

   # Property wurde geladen, sonst Abbruch
   $self-{_in_storage}  
!exists($self-{_property}-{_storage}-{$property})

   and croak Property $property not loaded;

   my $value = $_;

   # überprüfe neuen Wert auf Gültigkeit, sonst Abbruch
   defined($check_code)  !$check_code-($self, $_)
   and croak Invalid value for $property property;

   if( !defined($self-{_in_storage}) ) {
   # status schammiges Objekt, dann alles laden als from 
storage


   # ist neuer Wert != alter Wert, warnung ausgeben
   if( defined($_) ^ defined($value) or defined($_)  $_ 
ne $value ) {
   carp Property $property from database are 
inconsistent;

   $self-{_property}-{_storage}-{$property} = $value;
   }
   else {
   $self-{_property}-{_storage}-{$property} = $_;
   }

   }
   # wenn Objekt in der Datenbank
   elsif( $self-{_in_storage} ) {
   # lösche dirty-Status, wird neu berechnet
   delete($self-{_property}-{_dirty}-{$property});

   # ist neuer Wert != alter Wert, dirty-Status neu setzten
   defined($_) ^ 
defined($self-{_property}-{_storage}-{$property})

   and $self-{_property}-{_dirty}-{$property} = undef;

   # ist neuer Wert != alter Wert, dirty-Status neu setzten
   defined($_)  $_ ne 
$self-{_property}-{_storage}-{$property}

   and $self-{_property}-{_dirty}-{$property} = undef;
   }
   # wenn nicht in der Datenbank
   else {
   # auf jeden Fall auf dirty setzten
   $self-{_property}-{_dirty}-{$property} = undef
   }

   return $self-{_property}-{_current}-{$property} = $_;
   }

   croak Too many arguments for $property method;
   };
}

sub new {
   my ($class, @args) = @_;

   @args
   and croak q{Can't call method new with arguments};

   my $self = {
   _property   = {
   _current   = {},
   _storage   = {},
   _dirty = {},
   },
   _in_storage = undef,
   };

   bless($self, $class);

   return $self;
}

sub create {
   my ($class, @args) = @_;

   @args % 2
   and croak wrong count of arguments;

   my %customer_row = @args;

   # erstelle Objekt und setzte übergebene Parameter
   my $self = $class-new();
   $self-in_storage(0);
   $self-$_($customer_row{$_})  for( keys(%customer_row) );

   return $self;
}

sub in_storage {
   my ($self, $in_storage) = @_;

   if( @_ == 1 ) {
   return $self-{_in_storage};
   }

   if( @_ == 2 ) {
   if( !defined($in_storage) ) {
   $self-{_property}-{_storage}-{$_} = 
$self-{_property}-{_current}-{$_}  for( $self-is_changed );

   $self-{_property}-{_dirty} = {};
   }
   return $self-{_in_storage} =