Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 23:06, David Schmidt wrote:

> On 31 October 2012 00:00, Tomas Doran  wrote:
>> 
>> On 30 Oct 2012, at 16:52, Craig Chant wrote:
>> 
>>> I seem stuck with implementing my first view / template.
>>> 
>>> I have a controller Login.pm
>>> 
>>> I ran the view helper script ‘create view HTML HTML::template’
>>> 
>> 
>> This can't possibly have worked? You mean create view HTML HTML::Template 
>> right?
>> 
>>> As per the tutorial I’ve added the following to the config section of 
>>> MyApp.pm
>>> 
>>>TEMPLATE_EXTENSION => '.tp',
>> 
>> This needs to be inside the following block
>> 
>>>'View::HTML' => {
>>>#Set the location for templates files
>>>INCLUDE_PATH => [
>>>__PACKAGE__->path_to( 'root', 'src' ),
>>>],
>>>},
> 
> C::M::Tutorial says otherwise
> 
> http://search.cpan.org/~zarquon/Catalyst-Manual-5.9004/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod#Create_a_Catalyst_View


Sorry, but you're wrong.

The tutorial says:

"Edit lib/MyApp/View/HTML.pm and you should see something similar to the 
following:"

The OP says: "As per the tutorial I’ve added the following to the config 
section of MyApp.pm"

So, the OP has done something totally different to what the tutorial says, and 
thus it will behave differently.

If he moves that line to inside the View (as the tutorial suggests), it'll work.

If he moves it to inside the 'View::HTML' block in MyApp.pm, thus namespacing 
it into the appropriate component, it'll work.

Where it is right now - it will be ignored.

Cheers
t0m



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


Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread David Schmidt
On 31 October 2012 00:00, Tomas Doran  wrote:
>
> On 30 Oct 2012, at 16:52, Craig Chant wrote:
>
>> I seem stuck with implementing my first view / template.
>>
>> I have a controller Login.pm
>>
>> I ran the view helper script ‘create view HTML HTML::template’
>>
>
> This can't possibly have worked? You mean create view HTML HTML::Template 
> right?
>
>> As per the tutorial I’ve added the following to the config section of 
>> MyApp.pm
>>
>> TEMPLATE_EXTENSION => '.tp',
>
> This needs to be inside the following block
>
>> 'View::HTML' => {
>> #Set the location for templates files
>> INCLUDE_PATH => [
>> __PACKAGE__->path_to( 'root', 'src' ),
>> ],
>> },

C::M::Tutorial says otherwise

http://search.cpan.org/~zarquon/Catalyst-Manual-5.9004/lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod#Create_a_Catalyst_View


>>
>> I have created a template in ‘root/src/login’  of login.tp
>>
>> In my controller I have …
>>
>> sub login :Path :Args(0) {
>> my ( $self, $c) = @_;
>>
>> $c->stash(template => 'login.tp');
>>
>> }
>>
>> But all I get is…
>>
>
> No idea.
>
>>
>> What am I doing wrong?
>>
>
> Not showing us the full debug output of starting the server and making the 
> request.
>
> Sorry to be harsh - but it's impossible to divine what code your app is 
> running without that output…
>
> Cheers
> t0m
>
>
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

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


Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 16:52, Craig Chant wrote:

> I seem stuck with implementing my first view / template.
>  
> I have a controller Login.pm
>  
> I ran the view helper script ‘create view HTML HTML::template’
>  

This can't possibly have worked? You mean create view HTML HTML::Template right?

> As per the tutorial I’ve added the following to the config section of MyApp.pm
>  
> TEMPLATE_EXTENSION => '.tp',   

This needs to be inside the following block

> 'View::HTML' => {
> #Set the location for templates files
> INCLUDE_PATH => [
> __PACKAGE__->path_to( 'root', 'src' ),
> ],
> },
>  
> I have created a template in ‘root/src/login’  of login.tp
>  
> In my controller I have …
>  
> sub login :Path :Args(0) {
> my ( $self, $c) = @_;
>
> $c->stash(template => 'login.tp');   
>  
> }
>  
> But all I get is…
>  

No idea.

>  
> What am I doing wrong?
>  

Not showing us the full debug output of starting the server and making the 
request.

Sorry to be harsh - but it's impossible to divine what code your app is running 
without that output…

Cheers
t0m


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


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 15:47, Hugh Barnard wrote:

> Hi 
> 
> On measurement in general, I'd recommend: Devel::NYTProf::Apache ; there's a 
> write up here:
> http://www.slideshare.net/bobcatfish/profiling-with-develnytprof 
> 

++

Personally, I'd not be using mod_perl if I could help it, but NYTProf is 
awesome!

> . It looks like I've been having performance problems because millions of 
> rows get blessed into objects, not sure of this but it looks like a DBIC 
> thing at the moment. 

Inflating a million objects is costly.

Are you really building an HTML page with a million rows? If so, why (isn't 
paging a better solution?)

I.e. I'd generally say you should either paginate things, or make the query 
return an aggregate set of results by doing the math or whatever at the DB 
server.

However, if you really do need to re-inflate a lot of stuff, look at 
DBIx::Class::ResultClass::HashRefInflator - given you only want the raw data 
and none of the clever, this is much much faster :)

Cheers
t0m


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


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 15:03, Craig Chant wrote:
> 
> Plus I always felt loading an entire module to re-arrange a tiny string seems 
> a bit OTT?

Yes, it is :)

If you know that re-arranging a string is all you're ever going to be doing, 
then sure - don't' do that..

However, usually when you're dealing with the US, then you're _also_ dealing 
with a time zone offset, right? You don't want to only show local format dates, 
but also local time zones.

As a case in point, right now (for this working week), we're out of daylight 
savings time in the UK, however they're still in daylight savings times on the 
east of the US…

I for one do not want to care about this sort of stuff, ever.

> Dunno, what's the overhead of DateTime?


Significantly less than the overhead of caring about time zones, ever. :-D

If you're only doing day resolution (or only UTC), it's less convincing…

But basically, I wouldn't care unless it specifically shows up as slow in a 
real profile - "premature optimisation is the root of all evil", etc. 

Cheers
t0m


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


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 14:39, Craig Chant wrote:

> Well I opted for putting my globals (methods and constants) in MyApp.pm
> 
> It's working grand with $c->myMethod or $c->MY_CONSTANT
> 
> I use to have them working as a bareword within my application , but 
> $c->MY_CONSTANT is just as easy!

It's also several times slower :)

Unless they are methods (which use state) or constants which are really config, 
they're really better off in a function based style.

Cheers
t0m


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


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 14:03, Craig Chant wrote:

> So it seems it’s OK to whack them in the main MyApp.pm , here is an example 
> of what is currently in a ‘MemberGlobs.pm’, which is ‘required’ in 90% of all 
> the perl scripts.



> I’m forever having to switch between UK dates and USA dates so have helper 
> methods.
>  
> Where do these go?

The example function was immutable, and side effect free.

As such, it's purely functional, and thus I'd import it (i.e. write a module 
which just exported functions, and export it from there).

> Also where do you put application global constants?

How constant is constants?

If it's configurable, it comes from the config file!

If it's a real constant (as per the functions above), same situation applies.

However, I'd suggest that if you need functions such as this, your entire 
approach is broken! You should be inflating all dates and times into DateTime 
objects, and then using a correctly configured DateTime::Formatter::XXX to 
format them as appropriate for the output context.

This would mean that you'd set the date format generically for a user / page / 
whatever granularity you want, and you'd do conversion in one or two places - 
thus supporting the DRY principle, and allowing you to be much more flexible in 
future, when you need other date/time output formats.

Cheers
t0m


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


Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 20:08, Craig Chant wrote:

> The path/controller/action is resolving correctly now, but any response->body 
> change I make in the 'index :Path' action, isn't showing  when i refresh my 
> browser?

You're not showing us the debug output of the failing request, so it's very 
hard to help debug that request.

If you want this form of interactive help, you'd be much better off dropping 
into irc for interactive help, rather than the mailing list, which by it's 
nature is more asynchronous.

Hope to see you in irc!

Cheers
t0m



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


Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 20:08, Craig Chant wrote:

> I'm also convinced there is a caching issue, how can I refresh the browser on 
> a controller/action i've changed the response->body of and still get the old 
> output?
>  
> Please advise if there is some form of caching in Catalyst so I can turn it 
> off.

There is no caching, anywhere, unless you explicitly ask for / enable it.

Cheers
t0m



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


Re: [Catalyst] Unable to output anything in Root.pm -> 'auto'

2012-10-30 Thread Tomas Doran

On 30 Oct 2012, at 12:00, Craig Chant wrote:

> "What was the reason for not using DBIC again?"
> 
> The non-normalised DB with a  missing schema and the fact the data is spread 
> across two SQL servers on separate DSN's.


You didn't say anything there that didn't imply DBIC is fine.

The reason for not using DBIC again?

Also, your SQL abstraction has hilarious SQL injection holes - you do know 
about this, right?

> It's just before the return of the record set or count I was wondering if I 
> need to add '$sth->finish();' or '$dbh->disconnect();' - which I have in my 
> current (non-catalyst) app version of the class (module).

You're doing something wrong with DBI here!

> I also believe that DBIC gets all columns from all tables, which I don't 
> want, dunno, perhaps I'm missing something with DBIC, but I understand my 
> data the way I retrieve it and didn't think there was anything wrong with 
> using my SQL class, it has served me well for 10 years, and powers all my 
> current apps.

That's by default, and optional.

> One thing I have found already is the app doesn't seem to see real time SQL 
> updates even if I issue$sth->finish(); &   $dbh->disconnect(); at the end 
> of my method.
> 
> I make a manual change to SQL (switch the 'Locked' flag between 'yes' & 'no') 
> , refresh the app and it isn't registering the SQL change, so already it 
> seems something is being cached somewhere and I need to stop this, my apps 
> need to see DB changes instantly.

Again, you're doing something wrong or insane here - this is not normal, so you 
must be asking for it somehow.

Cheers
t0m



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


Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Francisco Obispo
I have found with time that enjoying a good meal is the best debugging tool.

Sent from my iPhone

On Oct 30, 2012, at 1:27 PM, Craig Chant  wrote:

> I had a hunch, so I uploaded the template to 'root' and bingo it found it
>  
> so this in MyApp.pm isn't working...
>  
> 'View::HTML' => {
> #Set the location for TT files
> INCLUDE_PATH => [
> __PACKAGE__->path_to( 'root', 'src' ),
> ],
> }
>  
> So does this attribute only work for TT template tool kit?
>  
> What's the flag for HTML::Template ? (this is the problem I'm having trying 
> to follow the tutorial!!!)
>  
> Also I now get the following error
>  
> Caught exception in Members::View::HTML->process "HTML::Template : Attempt to 
> set nonexistent parameter 'base' - this parameter name doesn't match any 
> declarations in the template file : (die_on_bad_params => 1) at 
> C:/Perl/site/lib/Catalyst/View/HTML/Template.pm line 99"
>  
> This is what I have in my HTML View...
>  
> package Members::View::HTML;
> use strict;
> use base 'Catalyst::View::HTML::Template';
> __PACKAGE__->config(
> TEMPLATE_EXTENSION => '.tp',
> render_die => 1,
> );
> 1;
> So how do I set the path for templates when using HTML::Template, why is it 
> falling over with the auto generated code in the View? And why isn't the 
> browser showing changed content when refreshed?
>  
> From: Craig Chant [cr...@homeloanpartnership.com]
> Sent: 30 October 2012 20:08
> To: The elegant MVC web framework
> Subject: RE: [Catalyst] I'm loosing the plot here? - Controller behaviour 
> that makes no sense
> 
> I've done the tutorial Debian VM walkthrough.
>  
> I stopped at DBIC / CRUD, and I keep referring back to the tutorial, but it's 
> very hard to follow when it is using examples for a templating system / ORM / 
> CRUD and OS i'm not using.
>  
> I'm also convinced there is a caching issue, how can I refresh the browser on 
> a controller/action i've changed the response->body of and still get the old 
> output?
>  
> Please advise if there is some form of caching in Catalyst so I can turn it 
> off.
>  
> I'm still unable to get the template to work, regardless of what I call it!
>  
> here is the output from the server..
>  
> [debug] Debug messages enabled
> [debug] Statistics enabled
> [debug] Loaded plugins:
> ..
> | Catalyst::Plugin::ConfigLoader  0.30   |
> | Catalyst::Plugin::Session  0.35|
> | Catalyst::Plugin::Session::State::Cookie  0.17 |
> | Catalyst::Plugin::Session::Store::FastMmap 0.16   |
> | Catalyst::Plugin::StackTrace  0.11 |
> ''
> [debug] Loaded dispatcher "Catalyst::Dispatcher"
> [debug] Loaded engine "Catalyst::Engine"
> [debug] Found home "C:\Websites\members"
> [debug] Loaded Config "C:\Websites\members\members.conf"
> [debug] Session Store file: C:\Users\admin\AppData\Local\Temp\1\members\
> ession_data
> [debug] Loaded components:
> .-+--.
> | Class   | Type |
> +-+--+
> | Members::Controller::Login  | instance |
> | Members::Controller::Root   | instance |
> | Members::Model::DBI | instance |
> | Members::Model::Members | instance |
> | Members::Model::Sql | class|
> | Members::View::HTML | instance |
> '-+--'
> [debug] Loaded Private actions:
> .--+--+--.
> | Private  | Class| Method   |
> +--+--+--+
> | /default | Members::Controller::Root| default  |
> | /end | Members::Controller::Root| end  |
> | /index   | Members::Controller::Root| index|
> | /begin   | Members::Controller::Root| begin|
> | /login/index | Members::Controller::Login   | index|
> | /login/login | Members::Controller::Login   | login|
> '--+--+--'
> [debug] Loaded Path actions:
> .-+--.
> | Path| Private

Re: [Catalyst] Unable to output anything in Root.pm -> 'auto'

2012-10-30 Thread Kieren Diment


On 30/10/2012, at 11:00 PM, Craig Chant wrote:

> "What was the reason for not using DBIC again?"
> 
> The non-normalised DB with a  missing schema and the fact the data is spread 
> across two SQL servers on separate DSN's.
> 

Be sure to use DBIx::Connector for connection management 
(https://metacpan.org/search?q=DBIx%3A%3AConnector), thus you get one of the 
compelling DBIC features but still get to use DBI.

> I also want my data in a way I can manipulate it, maybe you are all going to 
> fall down in shock and horror, but I get my records and pass them back as an 
> array of hashes (recordset), I then play with them , manipulate them, and do 
> all sorts of stuff with them.
> 
> ORM / DBIC doesn't seem to give you this type of access, it wants a DB schema 
> with relationship mapping to dynamically create all the 1-many / many - many 
> etc Models and relationships, which won't work with our system, from what I 
> can tell.
> 
> This is my SQL helper class (well two methods as an example)
> 
> # Get SQL Routine
> sub getSQL {
> 
>#_0 = Self
>#_1 = Table
>#_2 = Columns
>#_3 = Where
>#_4 = Order By
> 
>my ($self,$table,$columns,$where,$order) = @_;
> 
># Build SQL Statement
>my $sel = "SELECT $columns FROM $table WHERE $where";
> 
># Check for ORDER BY
>if(defined $order){$sel .= " ORDER BY $order";}
> 
># Connect
>my $dbh = $self->dbh;
> 
># set long read because SQL requires it for ODBC
>$dbh->{LongReadLen} = 9;
> 
># Run SQL Command
>my $sth = $db->prepare("$sel") || $self->sql_error("Error in getSQL (Web 
> Server): $sel");
>$sth->execute();
> 
># Declare recordset array
>my @rs;
> 
># Loop SQL & build recordset
>while (my $ref = $sth->fetchrow_hashref()) {
># Build Array of Hashes with SQL Data
>$rs[@rs] = \%$ref;
>}
> 
># Return record set
>@rs;
> 
> }
> 
> # Count SQL Routine
> sub cntSQL {
> 
>#_0 = Self
>#_1 = Table
>#_2 = Where
> 
>my ($self,$table,$where) = @_;
> 
>#Build SQL Statement
>my $sel = "SELECT COUNT(1) as COUNT FROM $table WHERE $where";
> 
># Connect
>my $dbh = $self->dbh;
> 
># Run SQL Command
>my $sth = $dbh->prepare("$sel") || $self->sql_error("Error in getSQL (Web 
> Server): $sel");
>$sth->execute();
> 
># Loop SQL Record Set
>while (my $ref = $sth->fetchrow_hashref()) {
># Build Array of Hashes with SQL Data
>$rs[@rs] = \%$ref;
>}
> 
># Return Count
>   $rs[0]->{'COUNT'};
> 
> }
> 
> It's just before the return of the record set or count I was wondering if I 
> need to add '$sth->finish();' or '$dbh->disconnect();' - which I have in my 
> current (non-catalyst) app version of the class (module).
> 
> I also believe that DBIC gets all columns from all tables, which I don't 
> want, dunno, perhaps I'm missing something with DBIC, but I understand my 
> data the way I retrieve it and didn't think there was anything wrong with 
> using my SQL class, it has served me well for 10 years, and powers all my 
> current apps.
> 
> How would I use DBIC to get records from two separate DSN's and merge 
> recordsets?
> 
> In my concrete Catalyst::Model I have...
> 
># Check if system locked
>if($self->cntSQL('IsLock',"Locked='yes'")){
>$c->response->body('Sorry, system is currently undergoing 
> maintenance.Please try again later.' );
>return 1;
>}
> 
> One thing I have found already is the app doesn't seem to see real time SQL 
> updates even if I issue$sth->finish(); &   $dbh->disconnect(); at the end 
> of my method.
> 
> I make a manual change to SQL (switch the 'Locked' flag between 'yes' & 'no') 
> , refresh the app and it isn't registering the SQL change, so already it 
> seems something is being cached somewhere and I need to stop this, my apps 
> need to see DB changes instantly.
> 
> Your advice is appreciated.
> 
> Craig.
> 
> -Original Message-
> From: Rob Brown [mailto:r...@intelcompute.com]
> Sent: 29 October 2012 22:30
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Unable to output anything in Root.pm -> 'auto'
> 
> basically...
> 
> $sth->finish if you've finished with the results of that statement, ie, 
> you've looped through the rows and are now done.
> 
> $dbh->disconnect if you've finished with the database connection, tho now you 
> start to think about working in a persistent environment, where you may never 
> disconnect from the database, and/or have some connection caching setup.
> 
> This is where DBIx::Class just takes of all this for you - it does sound like 
> you're re-inventing a lot here.
> 
> What was the reason for not using DBIC again?
> 
> 
> 
> 
> On 10/29/2012 10:10 PM, Craig Chant wrote:
>> I finally got to grips with extending my own class with the inbuilt $c->dbh.
>> 
>> But am unsure whether I am mean to issue either...
>> 
>> $sth->finish();
>> 
>> or
>> 
>>$dbh->disconnect();
>>

Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Kieren Diment
So it doesn't really matter that you eventually don't intend to use TT, you 
still need a solid grounding in the core concepts which the tutorial will give 
you.  Right now you're trying to pay attention to too many things at once.  Go 
through the tutorial.  Investment of 2-3 hours in that will save you many hours 
of head scratching down the track.

Meanwhile a quick search on cpan for Catalyst::View::HTML::Template will find 
you what you need.

On 31/10/2012, at 7:27 AM, Craig Chant wrote:

> I had a hunch, so I uploaded the template to 'root' and bingo it found it
> 
> 
> 
> so this in MyApp.pm isn't working...
> 
> 
> 
>'View::HTML' => {
>#Set the location for TT files
>INCLUDE_PATH => [
>__PACKAGE__->path_to( 'root', 'src' ),
>],
>}
> 
> 
> 
> So does this attribute only work for TT template tool kit?
> 
> 
> 
> What's the flag for HTML::Template ? (this is the problem I'm having trying 
> to follow the tutorial!!!)
> 
> 
> 
> Also I now get the following error
> 
> 
> 
> Caught exception in Members::View::HTML->process "HTML::Template : Attempt to 
> set nonexistent parameter 'base' - this parameter name doesn't match any 
> declarations in the template file : (die_on_bad_params => 1) at 
> C:/Perl/site/lib/Catalyst/View/HTML/Template.pm line 99"
> 
> 
> 
> This is what I have in my HTML View...
> 
> 
> 
> package Members::View::HTML;
> 
> use strict;
> use base 'Catalyst::View::HTML::Template';
> 
> __PACKAGE__->config(
>TEMPLATE_EXTENSION => '.tp',
>render_die => 1,
>);
> 
> 1;
> 
> So how do I set the path for templates when using HTML::Template, why is it 
> falling over with the auto generated code in the View? And why isn't the 
> browser showing changed content when refreshed?
> 
> 
> 
> 
> From: Craig Chant [cr...@homeloanpartnership.com]
> Sent: 30 October 2012 20:08
> To: The elegant MVC web framework
> Subject: RE: [Catalyst] I'm loosing the plot here? - Controller behaviour 
> that makes no sense
> 
> 
> I've done the tutorial Debian VM walkthrough.
> 
> 
> 
> I stopped at DBIC / CRUD, and I keep referring back to the tutorial, but it's 
> very hard to follow when it is using examples for a templating system / ORM / 
> CRUD and OS i'm not using.
> 
> 
> 
> I'm also convinced there is a caching issue, how can I refresh the browser on 
> a controller/action i've changed the response->body of and still get the old 
> output?
> 
> 
> 
> Please advise if there is some form of caching in Catalyst so I can turn it 
> off.
> 
> 
> 
> I'm still unable to get the template to work, regardless of what I call it!
> 
> 
> 
> here is the output from the server..
> 
> 
> 
> [debug] Debug messages enabled
> [debug] Statistics enabled
> [debug] Loaded plugins:
> ..
> | Catalyst::Plugin::ConfigLoader  0.30   |
> | Catalyst::Plugin::Session  0.35|
> | Catalyst::Plugin::Session::State::Cookie  0.17 |
> | Catalyst::Plugin::Session::Store::FastMmap  0.16   |
> | Catalyst::Plugin::StackTrace  0.11 |
> ''
> 
> [debug] Loaded dispatcher "Catalyst::Dispatcher"
> [debug] Loaded engine "Catalyst::Engine"
> [debug] Found home "C:\Websites\members"
> [debug] Loaded Config "C:\Websites\members\members.conf"
> [debug] Session Store file: C:\Users\admin\AppData\Local\Temp\1\members\
> ession_data
> [debug] Loaded components:
> .-+--.
> | Class   | Type |
> +-+--+
> | Members::Controller::Login  | instance |
> | Members::Controller::Root   | instance |
> | Members::Model::DBI | instance |
> | Members::Model::Members | instance |
> | Members::Model::Sql | class|
> | Members::View::HTML | instance |
> '-+--'
> 
> [debug] Loaded Private actions:
> .--+--+--.
> | Private  | Class| Method   |
> +--+--+--+
> | /default | Members::Controller::Root| default  |
> | /end | Members::Controller::Root| end  |
> | /index   | Members::Controller::Root| index|
> |

RE: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Craig Chant
I had a hunch, so I uploaded the template to 'root' and bingo it found it



so this in MyApp.pm isn't working...



'View::HTML' => {
#Set the location for TT files
INCLUDE_PATH => [
__PACKAGE__->path_to( 'root', 'src' ),
],
}



So does this attribute only work for TT template tool kit?



What's the flag for HTML::Template ? (this is the problem I'm having trying to 
follow the tutorial!!!)



Also I now get the following error



Caught exception in Members::View::HTML->process "HTML::Template : Attempt to 
set nonexistent parameter 'base' - this parameter name doesn't match any 
declarations in the template file : (die_on_bad_params => 1) at 
C:/Perl/site/lib/Catalyst/View/HTML/Template.pm line 99"



This is what I have in my HTML View...



package Members::View::HTML;

use strict;
use base 'Catalyst::View::HTML::Template';

__PACKAGE__->config(
TEMPLATE_EXTENSION => '.tp',
render_die => 1,
);

1;

So how do I set the path for templates when using HTML::Template, why is it 
falling over with the auto generated code in the View? And why isn't the 
browser showing changed content when refreshed?




From: Craig Chant [cr...@homeloanpartnership.com]
Sent: 30 October 2012 20:08
To: The elegant MVC web framework
Subject: RE: [Catalyst] I'm loosing the plot here? - Controller behaviour that 
makes no sense


I've done the tutorial Debian VM walkthrough.



I stopped at DBIC / CRUD, and I keep referring back to the tutorial, but it's 
very hard to follow when it is using examples for a templating system / ORM / 
CRUD and OS i'm not using.



I'm also convinced there is a caching issue, how can I refresh the browser on a 
controller/action i've changed the response->body of and still get the old 
output?



Please advise if there is some form of caching in Catalyst so I can turn it off.



I'm still unable to get the template to work, regardless of what I call it!



here is the output from the server..



[debug] Debug messages enabled
[debug] Statistics enabled
[debug] Loaded plugins:
..
| Catalyst::Plugin::ConfigLoader  0.30   |
| Catalyst::Plugin::Session  0.35|
| Catalyst::Plugin::Session::State::Cookie  0.17 |
| Catalyst::Plugin::Session::Store::FastMmap  0.16   |
| Catalyst::Plugin::StackTrace  0.11 |
''

[debug] Loaded dispatcher "Catalyst::Dispatcher"
[debug] Loaded engine "Catalyst::Engine"
[debug] Found home "C:\Websites\members"
[debug] Loaded Config "C:\Websites\members\members.conf"
[debug] Session Store file: C:\Users\admin\AppData\Local\Temp\1\members\
ession_data
[debug] Loaded components:
.-+--.
| Class   | Type |
+-+--+
| Members::Controller::Login  | instance |
| Members::Controller::Root   | instance |
| Members::Model::DBI | instance |
| Members::Model::Members | instance |
| Members::Model::Sql | class|
| Members::View::HTML | instance |
'-+--'

[debug] Loaded Private actions:
.--+--+--.
| Private  | Class| Method   |
+--+--+--+
| /default | Members::Controller::Root| default  |
| /end | Members::Controller::Root| end  |
| /index   | Members::Controller::Root| index|
| /begin   | Members::Controller::Root| begin|
| /login/index | Members::Controller::Login   | index|
| /login/login | Members::Controller::Login   | login|
'--+--+--'

[debug] Loaded Path actions:
.-+--.
| Path| Private  |
+-+--+
| /   | /index   |
| /...| /default |
| /login/ 

RE: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Craig Chant
I've done the tutorial Debian VM walkthrough.



I stopped at DBIC / CRUD, and I keep referring back to the tutorial, but it's 
very hard to follow when it is using examples for a templating system / ORM / 
CRUD and OS i'm not using.



I'm also convinced there is a caching issue, how can I refresh the browser on a 
controller/action i've changed the response->body of and still get the old 
output?



Please advise if there is some form of caching in Catalyst so I can turn it off.



I'm still unable to get the template to work, regardless of what I call it!



here is the output from the server..



[debug] Debug messages enabled
[debug] Statistics enabled
[debug] Loaded plugins:
..
| Catalyst::Plugin::ConfigLoader  0.30   |
| Catalyst::Plugin::Session  0.35|
| Catalyst::Plugin::Session::State::Cookie  0.17 |
| Catalyst::Plugin::Session::Store::FastMmap  0.16   |
| Catalyst::Plugin::StackTrace  0.11 |
''

[debug] Loaded dispatcher "Catalyst::Dispatcher"
[debug] Loaded engine "Catalyst::Engine"
[debug] Found home "C:\Websites\members"
[debug] Loaded Config "C:\Websites\members\members.conf"
[debug] Session Store file: C:\Users\admin\AppData\Local\Temp\1\members\
ession_data
[debug] Loaded components:
.-+--.
| Class   | Type |
+-+--+
| Members::Controller::Login  | instance |
| Members::Controller::Root   | instance |
| Members::Model::DBI | instance |
| Members::Model::Members | instance |
| Members::Model::Sql | class|
| Members::View::HTML | instance |
'-+--'

[debug] Loaded Private actions:
.--+--+--.
| Private  | Class| Method   |
+--+--+--+
| /default | Members::Controller::Root| default  |
| /end | Members::Controller::Root| end  |
| /index   | Members::Controller::Root| index|
| /begin   | Members::Controller::Root| begin|
| /login/index | Members::Controller::Login   | index|
| /login/login | Members::Controller::Login   | login|
'--+--+--'

[debug] Loaded Path actions:
.-+--.
| Path| Private  |
+-+--+
| /   | /index   |
| /...| /default |
| /login/ | /login/index |
| /login/login/   | /login/login |
'-+--'

[info] HLP_Members powered by Catalyst 5.90015
HTTP::Server::PSGI: Accepting connections at http://0:3000/



The path/controller/action is resolving correctly now, but any response->body 
change I make in the 'index :Path' action, isn't showing  when i refresh my 
browser?



And I still cannot get the template to work?



How do I find out where it thinks the template should be?


From: Tim Anderson [tja...@gmail.com]
Sent: 30 October 2012 17:57
To: The elegant MVC web framework
Subject: Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that 
makes no sense

Craig,

Might I suggest following Lukas' advice from yesterday and working through the 
tutorial before building your own site.  Catalyst is a great framework but it's 
not trivial, and I had several of the same kinds of questions when I first 
started out.

I clued in on your 'when neither output should show' statement; what are you 
expecting from 'mydomain:port/login' in your example.  It looks to me like 
/login should be matching your Login controller, and because you haven't 
specified a further path, your output is going to be 'this sucks', from the 
index function.

-Tim



This Email and any attac

Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Tim Anderson
Craig,

Might I suggest following Lukas' advice from yesterday and working through
the tutorial before building your own site.  Catalyst is a great framework
but it's not trivial, and I had several of the same kinds of questions when
I first started out.

I clued in on your 'when neither output should show' statement; what are
you expecting from 'mydomain:port/login' in your example.  It looks to me
like /login should be matching your Login controller, and because you
haven't specified a further path, your output is going to be 'this sucks',
from the index function.

-Tim


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


Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Lars Balker
On Tue, Oct 30, 2012 at 6:39 PM, Craig Chant
wrote:

>  Please advise why the following URL
>
>
>
> ‘mydomain:port/login’
>
>
>
> Produces “Matched Members::Controller::Login in Login.”
>
> sub index :Path :Args(0) {
>
> sub loginPage :Path :Args(0) {
>

Because having two empty :Path is not well defined - the latter overwrites
the former (in this case?).

Try with :Path('login') or :Local on the second one (and see
Catalyst::Manual::Intro)
-- 
Lars Balker  Consult::Perl
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread David Schmidt
Can you show us the startup output of your development server (start it in
debug mode)

david

On 30 October 2012 18:39, Craig Chant  wrote:

>  Please advise why the following URL
>
>
>
> ‘mydomain:port/login’
>
>
>
> Produces “Matched Members::Controller::Login in Login.”
>
>
>
> When the Login controller has …
>
>
>
> package Members::Controller::Login;
>
> use Moose;
>
> use namespace::autoclean;
>
>
>
> BEGIN { extends 'Catalyst::Controller'; }
>
>
>
> sub index :Path :Args(0) {
>
> my ( $self, $c ) = @_;
>
>
>
> $c->response->body('this sucks');
>
> }
>
>
>
> sub loginPage :Path :Args(0) {
>
> my ( $self, $c) = @_;
>
>
>
> $c->stash(template => 'login');
>
> }
>
>
>
>
>
> __PACKAGE__->meta->make_immutable;
>
>
>
> 1;
>
>
>
> The devel server shows…
>
>
>
> Caught exception in Members::View::HTML->process "HTML::Template->new() :
> Cannot open included file login : file not found. at
> C:/Perl/lib/HTML/Template.pm line 1813
>
> For the same URL , when neither output should show?
>
>
>
> Is something seriously wrong with Catalyst and IIS7 / ActiveState Perl ?
>
>
>
> I thought the URL was ‘domain:port/controller/action’ ?
>
>
>
> Is this how it is meant to work?
>
>
>
> All I get for ‘mydomain:port/login/loginPage’ – is a 404 not found?
>
>
>
> Why won’t any of this work?
>
>
>
>
>
> *Craig Chant*
>
> I.T. Manager
>
> [image: Description: cid:image001.png@01CD5F4A.17E848D0]
>
> Main Line01903 602664
>
> Direct Line   01903 227753
>
> Visit our website http://www.homeloanpartnership.com
>
> *HomeLoan Partnership have been named the Best Mortgage Network, 2012, at
> the myintroducer.com Industry Awards*
>
>
>  This Email and any attachments contain confidential information and is
> intended solely for the individual to whom it is addressed. If this Email
> has been misdirected, please notify the author as soon as possible. If you
> are not the intended recipient you must not disclose, distribute, copy,
> print or rely on any of the information contained, and all copies must be
> deleted immediately. Whilst we take reasonable steps to try to identify any
> software viruses, any attachments to this e-mail may nevertheless contain
> viruses, which our anti-virus software has failed to identify. You should
> therefore carry out your own anti-virus checks before opening any
> documents. HomeLoan Partnership will not accept any liability for damage
> caused by computer viruses emanating from any attachment or other document
> supplied with this e-mail. HomeLoan Partnership reserves the right to
> monitor and archive all e-mail communications through its network. No
> representative or employee of HomeLoan Partnership has the authority to
> enter into any contract on behalf of HomeLoan Partnership by email.
> HomeLoan Partnership is a trading name of H L Partnership Limited,
> registered in England and Wales with Registration Number 5011722.
> Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership
> Limited is authorised and regulated by the Financial Services Authority.
>
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
<>___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] I'm loosing the plot here? - Controller behaviour that makes no sense

2012-10-30 Thread Craig Chant
Please advise why the following URL

'mydomain:port/login'

Produces "Matched Members::Controller::Login in Login."

When the Login controller has ...

package Members::Controller::Login;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller'; }

sub index :Path :Args(0) {
my ( $self, $c ) = @_;

$c->response->body('this sucks');
}

sub loginPage :Path :Args(0) {
my ( $self, $c) = @_;

$c->stash(template => 'login');
}


__PACKAGE__->meta->make_immutable;

1;

The devel server shows...

Caught exception in Members::View::HTML->process "HTML::Template->new() : 
Cannot open included file login : file not found. at 
C:/Perl/lib/HTML/Template.pm line 1813
For the same URL , when neither output should show?

Is something seriously wrong with Catalyst and IIS7 / ActiveState Perl ?

I thought the URL was 'domain:port/controller/action' ?

Is this how it is meant to work?

All I get for 'mydomain:port/login/loginPage' - is a 404 not found?

Why won't any of this work?


Craig Chant
I.T. Manager
[Description: cid:image001.png@01CD5F4A.17E848D0]
Main Line01903 602664
Direct Line   01903 227753
Visit our website http://www.homeloanpartnership.com
HomeLoan Partnership have been named the Best Mortgage Network, 2012, at the 
myintroducer.com Industry Awards

This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.
<>___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Craig Chant
Hi Rob,

As I said, I've tried that also to no avail :-(

I thought the point of setting the template default extension is so you don't 
have to provide it?

Shouldn't 'login/login' work?

I can't even get the controller to work?

"mydomain:port/login/login " just gives me a 404 not found error?

Shouldn't

 sub login :Local :Args(0) {
my ( $self, $c) = @_;

$c->stash(template => 'login');
}

Map to "mydomain:port/login/login"

Why do seem to be going no-where fast with Catalyst?

Craig.

-Original Message-
From: Rob Brown [mailto:r...@intelcompute.com]
Sent: 30 October 2012 16:58
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Can't get view / template to work ?

the paths are from /root/src (as per the config), so if you've created another 
folder called "login" and put the file in there, you'd need to say...

$c->stash(template => 'login/login.tp');


On 10/30/2012 04:52 PM, Craig Chant wrote:
> I seem stuck with implementing my first view / template.
>
> I have a controller Login.pm
>
> I ran the view helper script 'create view HTML HTML::template'
>
> As per the tutorial I've added the following to the config section of
> MyApp.pm
>
> TEMPLATE_EXTENSION => '.tp',
>
> 'View::HTML' => {
>
> #Set the location for templates files
>
> INCLUDE_PATH => [
>
> __PACKAGE__->path_to( 'root', 'src' ),
>
> ],
>
> },
>
> I have created a template in 'root/src/login' of login.tp
>
> In my controller I have ...
>
> sub login :Path :Args(0) {
>
> my ( $self, $c) = @_;
>
> $c->stash(template => 'login.tp');
>
> }
>
> But all I get is...
>
> Caught exception in Members::View::HTML->process
> "HTML::Template->new()
> : Cannot open included file login.tp : file not found. at
> C:/Perl/lib/HTML/Template.pm line 1813
>
> I've also tried..
>
> $c->stash(template => 'login');
>
> $c->stash(template => 'login/login');
>
> $c->stash(template => 'login/login.tp');
>
> None of which seem to work?
>
> What am I doing wrong?
>
> */Craig Chant/*
>
> I.T. Manager
>
> Description: cid:image001.png@01CD5F4A.17E848D0
>
> Main Line 01903 602664
>
> Direct Line 01903 227753
>
> Visit our website http://www.homeloanpartnership.com
>
> *HomeLoan Partnership have been named the Best Mortgage Network, 2012,
> at the myintroducer.com Industry Awards*
>
> This Email and any attachments contain confidential information and is
> intended solely for the individual to whom it is addressed. If this
> Email has been misdirected, please notify the author as soon as
> possible. If you are not the intended recipient you must not disclose,
> distribute, copy, print or rely on any of the information contained,
> and all copies must be deleted immediately. Whilst we take reasonable
> steps to try to identify any software viruses, any attachments to this
> e-mail may nevertheless contain viruses, which our anti-virus software
> has failed to identify. You should therefore carry out your own
> anti-virus checks before opening any documents. HomeLoan Partnership
> will not accept any liability for damage caused by computer viruses
> emanating from any attachment or other document supplied with this e-mail.
> HomeLoan Partnership reserves the right to monitor and archive all
> e-mail communications through its network. No representative or
> employee of HomeLoan Partnership has the authority to enter into any
> contract on behalf of HomeLoan Partnership by email. HomeLoan
> Partnership is a trading name of H L Partnership Limited, registered
> in England and Wales with Registration Number 5011722. Registered
> office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is
> authorised and regulated by the Financial Services Authority.
>
>
>
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

--
IntelCompute
Web Design & Online Marketing Experts

http://www.intelcompute.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan P

Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Rob Brown

ignore that then, didn't read all of your message  :-/


On 10/30/2012 04:58 PM, Rob Brown wrote:

the paths are from /root/src (as per the config), so if you've created
another folder called "login" and put the file in there, you'd need to
say...

$c->stash(template => 'login/login.tp');


On 10/30/2012 04:52 PM, Craig Chant wrote:

I seem stuck with implementing my first view / template.

I have a controller Login.pm

I ran the view helper script ‘create view HTML HTML::template’

As per the tutorial I’ve added the following to the config section of
MyApp.pm

TEMPLATE_EXTENSION => '.tp',

'View::HTML' => {

#Set the location for templates files

INCLUDE_PATH => [

__PACKAGE__->path_to( 'root', 'src' ),

],

},

I have created a template in ‘root/src/login’ of login.tp

In my controller I have …

sub login :Path :Args(0) {

my ( $self, $c) = @_;

$c->stash(template => 'login.tp');

}

But all I get is…

Caught exception in Members::View::HTML->process "HTML::Template->new()
: Cannot open included file login.tp : file not found. at
C:/Perl/lib/HTML/Template.pm line 1813

I’ve also tried..

$c->stash(template => 'login');

$c->stash(template => 'login/login');

$c->stash(template => 'login/login.tp');

None of which seem to work?

What am I doing wrong?

*/Craig Chant/*

I.T. Manager

Description: cid:image001.png@01CD5F4A.17E848D0

Main Line 01903 602664

Direct Line 01903 227753

Visit our website http://www.homeloanpartnership.com

*HomeLoan Partnership have been named the Best Mortgage Network, 2012,
at the myintroducer.com Industry Awards*

This Email and any attachments contain confidential information and is
intended solely for the individual to whom it is addressed. If this
Email has been misdirected, please notify the author as soon as
possible. If you are not the intended recipient you must not disclose,
distribute, copy, print or rely on any of the information contained, and
all copies must be deleted immediately. Whilst we take reasonable steps
to try to identify any software viruses, any attachments to this e-mail
may nevertheless contain viruses, which our anti-virus software has
failed to identify. You should therefore carry out your own anti-virus
checks before opening any documents. HomeLoan Partnership will not
accept any liability for damage caused by computer viruses emanating
from any attachment or other document supplied with this e-mail.
HomeLoan Partnership reserves the right to monitor and archive all
e-mail communications through its network. No representative or employee
of HomeLoan Partnership has the authority to enter into any contract on
behalf of HomeLoan Partnership by email. HomeLoan Partnership is a
trading name of H L Partnership Limited, registered in England and Wales
with Registration Number 5011722. Registered office: 26-34 Old Street,
London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by
the Financial Services Authority.



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




--
IntelCompute
Web Design & Online Marketing Experts

http://www.intelcompute.com

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


Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Len Jaffe
On Tue, Oct 30, 2012 at 12:58 PM, Rob Brown  wrote:

> the paths are from /root/src (as per the config), so if you've created
> another folder called "login" and put the file in there, you'd need to
> say...
> $c->stash(template => 'login/login.tp');
>

Or you could add /root/src/login as a path to the TT config.

Len.

-- 
lenja...@jaffesystems.com   614-404-4214 www.volunteerable.net
Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
Greenbar : Grubmaster: 2012-2009, Grub
Asst: 2008, Trained: 2007.
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Can't get view / template to work ?

2012-10-30 Thread Rob Brown
the paths are from /root/src (as per the config), so if you've created 
another folder called "login" and put the file in there, you'd need to 
say...


$c->stash(template => 'login/login.tp');


On 10/30/2012 04:52 PM, Craig Chant wrote:

I seem stuck with implementing my first view / template.

I have a controller Login.pm

I ran the view helper script ‘create view HTML HTML::template’

As per the tutorial I’ve added the following to the config section of
MyApp.pm

TEMPLATE_EXTENSION => '.tp',

'View::HTML' => {

#Set the location for templates files

INCLUDE_PATH => [

__PACKAGE__->path_to( 'root', 'src' ),

],

},

I have created a template in ‘root/src/login’ of login.tp

In my controller I have …

sub login :Path :Args(0) {

my ( $self, $c) = @_;

$c->stash(template => 'login.tp');

}

But all I get is…

Caught exception in Members::View::HTML->process "HTML::Template->new()
: Cannot open included file login.tp : file not found. at
C:/Perl/lib/HTML/Template.pm line 1813

I’ve also tried..

$c->stash(template => 'login');

$c->stash(template => 'login/login');

$c->stash(template => 'login/login.tp');

None of which seem to work?

What am I doing wrong?

*/Craig Chant/*

I.T. Manager

Description: cid:image001.png@01CD5F4A.17E848D0

Main Line 01903 602664

Direct Line 01903 227753

Visit our website http://www.homeloanpartnership.com

*HomeLoan Partnership have been named the Best Mortgage Network, 2012,
at the myintroducer.com Industry Awards*

This Email and any attachments contain confidential information and is
intended solely for the individual to whom it is addressed. If this
Email has been misdirected, please notify the author as soon as
possible. If you are not the intended recipient you must not disclose,
distribute, copy, print or rely on any of the information contained, and
all copies must be deleted immediately. Whilst we take reasonable steps
to try to identify any software viruses, any attachments to this e-mail
may nevertheless contain viruses, which our anti-virus software has
failed to identify. You should therefore carry out your own anti-virus
checks before opening any documents. HomeLoan Partnership will not
accept any liability for damage caused by computer viruses emanating
from any attachment or other document supplied with this e-mail.
HomeLoan Partnership reserves the right to monitor and archive all
e-mail communications through its network. No representative or employee
of HomeLoan Partnership has the authority to enter into any contract on
behalf of HomeLoan Partnership by email. HomeLoan Partnership is a
trading name of H L Partnership Limited, registered in England and Wales
with Registration Number 5011722. Registered office: 26-34 Old Street,
London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by
the Financial Services Authority.



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


--
IntelCompute
Web Design & Online Marketing Experts

http://www.intelcompute.com

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


[Catalyst] Can't get view / template to work ?

2012-10-30 Thread Craig Chant
I seem stuck with implementing my first view / template.

I have a controller Login.pm

I ran the view helper script 'create view HTML HTML::template'

As per the tutorial I've added the following to the config section of MyApp.pm

TEMPLATE_EXTENSION => '.tp',
'View::HTML' => {
#Set the location for templates files
INCLUDE_PATH => [
__PACKAGE__->path_to( 'root', 'src' ),
],
},

I have created a template in 'root/src/login'  of login.tp

In my controller I have ...

sub login :Path :Args(0) {
my ( $self, $c) = @_;

$c->stash(template => 'login.tp');

}

But all I get is...

Caught exception in Members::View::HTML->process "HTML::Template->new() : 
Cannot open included file login.tp : file not found. at 
C:/Perl/lib/HTML/Template.pm line 1813

I've also tried..

$c->stash(template => 'login');
$c->stash(template => 'login/login');
$c->stash(template => 'login/login.tp');

None of which seem to work?

What am I doing wrong?

Craig Chant
I.T. Manager
[Description: cid:image001.png@01CD5F4A.17E848D0]
Main Line01903 602664
Direct Line   01903 227753
Visit our website http://www.homeloanpartnership.com
HomeLoan Partnership have been named the Best Mortgage Network, 2012, at the 
myintroducer.com Industry Awards

This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.
<>___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Hugh Barnard
Hi Craig, See below...

On 30 October 2012 16:15, Craig Chant  wrote:

>  Hi Hugh,
>
>
>
> I assume this is for Apache and I’m running IIS7, so I guess it isn’t
> compatible?
>
Although Japanese is a 'somewhat' family language, I can't read most of the
text in this:
 http://d.hatena.ne.jp/xaicron/ but it looks like an install of the
'mother' non-Apache module to Windows with Strawberry Perl. Obviously your
mileage may vary, but if you get anywhere, you'd be something of a pioneer
too, tell everyone.

>
>
> “It looks like I've been having performance problems because millions of
> rows get blessed into objects, not sure of this but it looks like a DBIC
> thing at the moment.”
>
>
>
> That’s not good, and is part of the issue of ORM (so I’ve read),  I’m not
> as old as you, but I’m still old school, get only the columns and rows you
> need when you need them, well that’s my take on it and it seems to work for
> me.
>
Depends, DBIC is often really 'natural' and less hand-coding but, like
everything, I think its limits need to be understood. For high performance
on big datasets, hand-rolled seems intuitively better in some cases.

>
>
> Regards,
>
>
>
> Craig.
>
>
>
> *From:* Hugh Barnard [mailto:hugh.barn...@gmail.com]
> *Sent:* 30 October 2012 15:47
> *To:* The elegant MVC web framework
>
> *Subject:* Re: [Catalyst] Global 'helper' methods
>
>
>
> Hi
>
> On measurement in general, I'd recommend: Devel::NYTProf::Apache ; there's
> a write up here:
> http://www.slideshare.net/bobcatfish/profiling-with-develnytprof
>
> I'm dealing with a largish Catalyst/mod_perl thing at the moment and it's
> been tremendously helpful. One tip is that it is very picky about closing
> the files that it needs to compile the profiles, I write these into /tmp
> and then crunch them with the command line tools.
>
> Incidentally, I am 62 and therefore pretty old-skool and not mad for
> ORM-everywhere. It looks like I've been having performance problems because
> millions of rows get blessed into objects, not sure of this but it looks
> like a DBIC thing at the moment. Currently I've 'cursor'-ed them:
>   my $cursor = $entries->cursor;
>   while ( my @row_values = $cursor->next ) {
> and that seems to give some improvements in that area...
>
> Best regards Hugh
>
> On 30 October 2012 15:24, Lukas Thiemeier 
> wrote:
>
> Hm... how to measure the overhead of a module?
>
> There is a XS version of the module which is used if you have a C
> compiler. I don't know the exact overhead, but I know that it is fast.
>
> I have no experience with the pure perl version of that module.
>
> If all you have to do with the dates is the simple string transformation
> you are right. As I said before: I recommend to use DT if you are
> working with dates a lot. Doing math on dates and times is annoying,
> because of leap years, epochs, timezones and so on. If you need this:
> Using DateTime is recommended. If not: Its not :)
>
> If you are ONLY using pure perl modules:
> You can include all required modules in your distribution. It should run
> on any perl installation, even in a shared host environment.
>
> App::FatPacker helps you doing this...
>
> But this doesn't work as soon as you use XS modules.
>
>
> On 10/30/2012 04:03 PM, Craig Chant wrote:
> > Thanks Lukas,
> >
> > I appreciate there is DateTime , though I have so much legacy code that
> uses my helper class re-writing everything will be a mammoth task.
> >
> > I hand rolled a lot when I first started out with Perl, didn't know much
> about CPAN or PPM, and couldn't load any modules that weren't part of the
> core install on the original 'shared' hosting I was using.
> >
> > Plus I always felt loading an entire module to re-arrange a tiny string
> seems a bit OTT?
> >
> > Dunno, what's the overhead of DateTime?
> >
> > Craig.
> >
> > -Original Message-
> > From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> > Sent: 30 October 2012 14:52
> > To: catalyst@lists.scsys.co.uk
> > Subject: Re: [Catalyst] Global 'helper' methods
> >
> > You can also define your constants in "YourApp/Constants.pl", and "use"
> > YourApp::Constants wherever you need them.
> >
> > YourApp/Constants.pm:
> >   use constant { FOO => 1 };
> >   1;
> >
> > Controller.pm:
> >
> >   use YourApp::Constants;
> >
> >   # and in some method
> >   ...
> >   my $global_foo = FOO;
> >
> > There might be a better way, but this works...
> >
> > For handling dates, I recommend "DateTime", available on cpan:
> >
> > Another reason to use DBIC:
> > DBIx::Class::Inflatecolumn::DateTime automatically transforms dates
> stored in a database into a DateTime object, which can be used like this:
> >
> > my $uk_string = $datetime->dmy('/');
> > my $us_string = $datetime->ymd('-');
> >
> > But DateTime is not related to DBIC, DBIC just makes using it easy.
> >
> > Use it if you have to work with dates a lot. It has lots of methods for
> outputting dates, times or both in different formats, and it allows
> datetime-math...
> >
> >

Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread David Schmidt
Perhaps it is feasible for you to bypass object inflation.

1)
"DBIx::Class is not built for speed, it's built for convenience and
ease of use, but sometimes you just need to get the data, and skip the
fancy objects."

http://search.cpan.org/~frew/DBIx-Class-0.08200/lib/DBIx/Class/Manual/Cookbook.pod#Skip_row_object_creation_for_faster_results

2)
"If the HashRefInflator solution above is not fast enough for you, you
can use a DBIx::Class to return values exactly as they come out of the
database"
http://search.cpan.org/~frew/DBIx-Class-0.08200/lib/DBIx/Class/Manual/Cookbook.pod#Get_raw_data_for_blindingly_fast_results

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


RE: [Catalyst] Global 'helper' methods

2012-10-30 Thread Craig Chant
Hi Hugh,

I assume this is for Apache and I'm running IIS7, so I guess it isn't 
compatible?

"It looks like I've been having performance problems because millions of rows 
get blessed into objects, not sure of this but it looks like a DBIC thing at 
the moment."

That's not good, and is part of the issue of ORM (so I've read),  I'm not as 
old as you, but I'm still old school, get only the columns and rows you need 
when you need them, well that's my take on it and it seems to work for me.

Regards,

Craig.

From: Hugh Barnard [mailto:hugh.barn...@gmail.com]
Sent: 30 October 2012 15:47
To: The elegant MVC web framework
Subject: Re: [Catalyst] Global 'helper' methods

Hi

On measurement in general, I'd recommend: Devel::NYTProf::Apache ; there's a 
write up here:
http://www.slideshare.net/bobcatfish/profiling-with-develnytprof

I'm dealing with a largish Catalyst/mod_perl thing at the moment and it's been 
tremendously helpful. One tip is that it is very picky about closing the files 
that it needs to compile the profiles, I write these into /tmp and then crunch 
them with the command line tools.

Incidentally, I am 62 and therefore pretty old-skool and not mad for 
ORM-everywhere. It looks like I've been having performance problems because 
millions of rows get blessed into objects, not sure of this but it looks like a 
DBIC thing at the moment. Currently I've 'cursor'-ed them:
  my $cursor = $entries->cursor;
  while ( my @row_values = $cursor->next ) {
and that seems to give some improvements in that area...

Best regards Hugh
On 30 October 2012 15:24, Lukas Thiemeier 
mailto:spamcatc...@thiemeier.net>> wrote:
Hm... how to measure the overhead of a module?

There is a XS version of the module which is used if you have a C
compiler. I don't know the exact overhead, but I know that it is fast.

I have no experience with the pure perl version of that module.

If all you have to do with the dates is the simple string transformation
you are right. As I said before: I recommend to use DT if you are
working with dates a lot. Doing math on dates and times is annoying,
because of leap years, epochs, timezones and so on. If you need this:
Using DateTime is recommended. If not: Its not :)

If you are ONLY using pure perl modules:
You can include all required modules in your distribution. It should run
on any perl installation, even in a shared host environment.

App::FatPacker helps you doing this...

But this doesn't work as soon as you use XS modules.

On 10/30/2012 04:03 PM, Craig Chant wrote:
> Thanks Lukas,
>
> I appreciate there is DateTime , though I have so much legacy code that uses 
> my helper class re-writing everything will be a mammoth task.
>
> I hand rolled a lot when I first started out with Perl, didn't know much 
> about CPAN or PPM, and couldn't load any modules that weren't part of the 
> core install on the original 'shared' hosting I was using.
>
> Plus I always felt loading an entire module to re-arrange a tiny string seems 
> a bit OTT?
>
> Dunno, what's the overhead of DateTime?
>
> Craig.
>
> -Original Message-
> From: Lukas Thiemeier 
> [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 14:52
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Global 'helper' methods
>
> You can also define your constants in "YourApp/Constants.pl", and "use"
> YourApp::Constants wherever you need them.
>
> YourApp/Constants.pm:
>   use constant { FOO => 1 };
>   1;
>
> Controller.pm:
>
>   use YourApp::Constants;
>
>   # and in some method
>   ...
>   my $global_foo = FOO;
>
> There might be a better way, but this works...
>
> For handling dates, I recommend "DateTime", available on cpan:
>
> Another reason to use DBIC:
> DBIx::Class::Inflatecolumn::DateTime automatically transforms dates stored in 
> a database into a DateTime object, which can be used like this:
>
> my $uk_string = $datetime->dmy('/');
> my $us_string = $datetime->ymd('-');
>
> But DateTime is not related to DBIC, DBIC just makes using it easy.
>
> Use it if you have to work with dates a lot. It has lots of methods for 
> outputting dates, times or both in different formats, and it allows 
> datetime-math...
>
>
> On 10/30/2012 03:39 PM, Craig Chant wrote:
>> Well I opted for putting my globals (methods and constants) in
>> MyApp.pm
>>
>> It's working grand with $c->myMethod or $c->MY_CONSTANT
>>
>> I use to have them working as a bareword within my application , but 
>> $c->MY_CONSTANT is just as easy!
>>
>> Many thanks for all the input and help, it really is appreciated.
>>
>> -Original Message-
>> From: Lukas Thiemeier 
>> [mailto:spamcatc...@thiemeier.net]
>> Sent: 30 October 2012 13:56
>> To: catalyst@lists.scsys.co.uk
>> Subject: Re: [Catalyst] Global 'helper' methods
>>
>> Hi Craig,
>>
>> Writing helpers in your main App.pm and using roles is not either-or.
>>

Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Hugh Barnard
Hi

On measurement in general, I'd recommend: Devel::NYTProf::Apache ; there's
a write up here:
http://www.slideshare.net/bobcatfish/profiling-with-develnytprof

I'm dealing with a largish Catalyst/mod_perl thing at the moment and it's
been tremendously helpful. One tip is that it is very picky about closing
the files that it needs to compile the profiles, I write these into /tmp
and then crunch them with the command line tools.

Incidentally, I am 62 and therefore pretty old-skool and not mad for
ORM-everywhere. It looks like I've been having performance problems because
millions of rows get blessed into objects, not sure of this but it looks
like a DBIC thing at the moment. Currently I've 'cursor'-ed them:
  my $cursor = $entries->cursor;
  while ( my @row_values = $cursor->next ) {
and that seems to give some improvements in that area...

Best regards Hugh

On 30 October 2012 15:24, Lukas Thiemeier  wrote:

> Hm... how to measure the overhead of a module?
>
> There is a XS version of the module which is used if you have a C
> compiler. I don't know the exact overhead, but I know that it is fast.
>
> I have no experience with the pure perl version of that module.
>
> If all you have to do with the dates is the simple string transformation
> you are right. As I said before: I recommend to use DT if you are
> working with dates a lot. Doing math on dates and times is annoying,
> because of leap years, epochs, timezones and so on. If you need this:
> Using DateTime is recommended. If not: Its not :)
>
> If you are ONLY using pure perl modules:
> You can include all required modules in your distribution. It should run
> on any perl installation, even in a shared host environment.
>
> App::FatPacker helps you doing this...
>
> But this doesn't work as soon as you use XS modules.
>
> On 10/30/2012 04:03 PM, Craig Chant wrote:
> > Thanks Lukas,
> >
> > I appreciate there is DateTime , though I have so much legacy code that
> uses my helper class re-writing everything will be a mammoth task.
> >
> > I hand rolled a lot when I first started out with Perl, didn't know much
> about CPAN or PPM, and couldn't load any modules that weren't part of the
> core install on the original 'shared' hosting I was using.
> >
> > Plus I always felt loading an entire module to re-arrange a tiny string
> seems a bit OTT?
> >
> > Dunno, what's the overhead of DateTime?
> >
> > Craig.
> >
> > -Original Message-
> > From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> > Sent: 30 October 2012 14:52
> > To: catalyst@lists.scsys.co.uk
> > Subject: Re: [Catalyst] Global 'helper' methods
> >
> > You can also define your constants in "YourApp/Constants.pl", and "use"
> > YourApp::Constants wherever you need them.
> >
> > YourApp/Constants.pm:
> >   use constant { FOO => 1 };
> >   1;
> >
> > Controller.pm:
> >
> >   use YourApp::Constants;
> >
> >   # and in some method
> >   ...
> >   my $global_foo = FOO;
> >
> > There might be a better way, but this works...
> >
> > For handling dates, I recommend "DateTime", available on cpan:
> >
> > Another reason to use DBIC:
> > DBIx::Class::Inflatecolumn::DateTime automatically transforms dates
> stored in a database into a DateTime object, which can be used like this:
> >
> > my $uk_string = $datetime->dmy('/');
> > my $us_string = $datetime->ymd('-');
> >
> > But DateTime is not related to DBIC, DBIC just makes using it easy.
> >
> > Use it if you have to work with dates a lot. It has lots of methods for
> outputting dates, times or both in different formats, and it allows
> datetime-math...
> >
> >
> > On 10/30/2012 03:39 PM, Craig Chant wrote:
> >> Well I opted for putting my globals (methods and constants) in
> >> MyApp.pm
> >>
> >> It's working grand with $c->myMethod or $c->MY_CONSTANT
> >>
> >> I use to have them working as a bareword within my application , but
> $c->MY_CONSTANT is just as easy!
> >>
> >> Many thanks for all the input and help, it really is appreciated.
> >>
> >> -Original Message-
> >> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> >> Sent: 30 October 2012 13:56
> >> To: catalyst@lists.scsys.co.uk
> >> Subject: Re: [Catalyst] Global 'helper' methods
> >>
> >> Hi Craig,
> >>
> >> Writing helpers in your main App.pm and using roles is not either-or.
> >>
> >> Roles are one possibility to modify your classes in a reusable way.
> >>
> >> If your helpers are really global, which means that they are used by
> all, or almost all your controllers, I would put them into your main
> application class.
> >>
> >> If you have more than one application which make use of the same
> >> helpers: Put them into a role:
> >>
> >> YourHelperRole.pm:
> >>
> >>   package YourHelperRole;
> >>   use Moose::Role;
> >>
> >>   has "some_attribute" => ( ... ); # if you need attributes
> >>
> >>   sub helpermethod1{
> >> my ($self, $other, $args) = @_;
> >> do_something();
> >>   }
> >>
> >>   sub helpermethod2{
> >> my ($self, $other, $args) 

Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Lukas Thiemeier
Hm... how to measure the overhead of a module?

There is a XS version of the module which is used if you have a C
compiler. I don't know the exact overhead, but I know that it is fast.

I have no experience with the pure perl version of that module.

If all you have to do with the dates is the simple string transformation
you are right. As I said before: I recommend to use DT if you are
working with dates a lot. Doing math on dates and times is annoying,
because of leap years, epochs, timezones and so on. If you need this:
Using DateTime is recommended. If not: Its not :)

If you are ONLY using pure perl modules:
You can include all required modules in your distribution. It should run
on any perl installation, even in a shared host environment.

App::FatPacker helps you doing this...

But this doesn't work as soon as you use XS modules.

On 10/30/2012 04:03 PM, Craig Chant wrote:
> Thanks Lukas,
> 
> I appreciate there is DateTime , though I have so much legacy code that uses 
> my helper class re-writing everything will be a mammoth task.
> 
> I hand rolled a lot when I first started out with Perl, didn't know much 
> about CPAN or PPM, and couldn't load any modules that weren't part of the 
> core install on the original 'shared' hosting I was using.
> 
> Plus I always felt loading an entire module to re-arrange a tiny string seems 
> a bit OTT?
> 
> Dunno, what's the overhead of DateTime?
> 
> Craig.
> 
> -Original Message-
> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 14:52
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Global 'helper' methods
> 
> You can also define your constants in "YourApp/Constants.pl", and "use"
> YourApp::Constants wherever you need them.
> 
> YourApp/Constants.pm:
>   use constant { FOO => 1 };
>   1;
> 
> Controller.pm:
> 
>   use YourApp::Constants;
> 
>   # and in some method
>   ...
>   my $global_foo = FOO;
> 
> There might be a better way, but this works...
> 
> For handling dates, I recommend "DateTime", available on cpan:
> 
> Another reason to use DBIC:
> DBIx::Class::Inflatecolumn::DateTime automatically transforms dates stored in 
> a database into a DateTime object, which can be used like this:
> 
> my $uk_string = $datetime->dmy('/');
> my $us_string = $datetime->ymd('-');
> 
> But DateTime is not related to DBIC, DBIC just makes using it easy.
> 
> Use it if you have to work with dates a lot. It has lots of methods for 
> outputting dates, times or both in different formats, and it allows 
> datetime-math...
> 
> 
> On 10/30/2012 03:39 PM, Craig Chant wrote:
>> Well I opted for putting my globals (methods and constants) in
>> MyApp.pm
>>
>> It's working grand with $c->myMethod or $c->MY_CONSTANT
>>
>> I use to have them working as a bareword within my application , but 
>> $c->MY_CONSTANT is just as easy!
>>
>> Many thanks for all the input and help, it really is appreciated.
>>
>> -Original Message-
>> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
>> Sent: 30 October 2012 13:56
>> To: catalyst@lists.scsys.co.uk
>> Subject: Re: [Catalyst] Global 'helper' methods
>>
>> Hi Craig,
>>
>> Writing helpers in your main App.pm and using roles is not either-or.
>>
>> Roles are one possibility to modify your classes in a reusable way.
>>
>> If your helpers are really global, which means that they are used by all, or 
>> almost all your controllers, I would put them into your main application 
>> class.
>>
>> If you have more than one application which make use of the same
>> helpers: Put them into a role:
>>
>> YourHelperRole.pm:
>>
>>   package YourHelperRole;
>>   use Moose::Role;
>>
>>   has "some_attribute" => ( ... ); # if you need attributes
>>
>>   sub helpermethod1{
>> my ($self, $other, $args) = @_;
>> do_something();
>>   }
>>
>>   sub helpermethod2{
>> my ($self, $other, $args) = @_;
>> do_something_different();
>>   }
>>
>>   no Moose::Role; # or use namespace::autoclean or MooseX::MarkAsMethod
>>   1;
>>
>> App.pm:
>>
>>   use Catalyst qw( ... );
>>   extends "Catalyst";
>>   with qw/YourHelperRole/;
>>
>>   ...
>>
>> In my opinion, extending your main App.pm with roles is only useful if you 
>> need the same helpers in different locations, too.
>> If you only need them for that single application,  avoid the overhead 
>> related to using roles.
>>
>> If you have helpers which are only needed by some controllers, create a role 
>> for your controllers. You can not only implement helpers in you roles, you 
>> can also create method-modifiers, which change the way your methods behave.
>>
>> Here is an example, which writes sth to the log, after the "delete"
>> method was called:
>>
>> YourLogRole.pm:
>>
>>   package YourLogRole;
>>
>>   use Moose::Role;
>>   requires qw/delete/; #die if the consuming class has no "delete"
>>
>>   after "delete" => sub{
>> my ($self, $c) = @_;
>> $c->log->debug("DELETE called");
>>   };
>>
>>   no Moose::Rol

RE: [Catalyst] Global 'helper' methods

2012-10-30 Thread Craig Chant
Thanks Lukas,

I appreciate there is DateTime , though I have so much legacy code that uses my 
helper class re-writing everything will be a mammoth task.

I hand rolled a lot when I first started out with Perl, didn't know much about 
CPAN or PPM, and couldn't load any modules that weren't part of the core 
install on the original 'shared' hosting I was using.

Plus I always felt loading an entire module to re-arrange a tiny string seems a 
bit OTT?

Dunno, what's the overhead of DateTime?

Craig.

-Original Message-
From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
Sent: 30 October 2012 14:52
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Global 'helper' methods

You can also define your constants in "YourApp/Constants.pl", and "use"
YourApp::Constants wherever you need them.

YourApp/Constants.pm:
  use constant { FOO => 1 };
  1;

Controller.pm:

  use YourApp::Constants;

  # and in some method
  ...
  my $global_foo = FOO;

There might be a better way, but this works...

For handling dates, I recommend "DateTime", available on cpan:

Another reason to use DBIC:
DBIx::Class::Inflatecolumn::DateTime automatically transforms dates stored in a 
database into a DateTime object, which can be used like this:

my $uk_string = $datetime->dmy('/');
my $us_string = $datetime->ymd('-');

But DateTime is not related to DBIC, DBIC just makes using it easy.

Use it if you have to work with dates a lot. It has lots of methods for 
outputting dates, times or both in different formats, and it allows 
datetime-math...


On 10/30/2012 03:39 PM, Craig Chant wrote:
> Well I opted for putting my globals (methods and constants) in
> MyApp.pm
>
> It's working grand with $c->myMethod or $c->MY_CONSTANT
>
> I use to have them working as a bareword within my application , but 
> $c->MY_CONSTANT is just as easy!
>
> Many thanks for all the input and help, it really is appreciated.
>
> -Original Message-
> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 13:56
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Global 'helper' methods
>
> Hi Craig,
>
> Writing helpers in your main App.pm and using roles is not either-or.
>
> Roles are one possibility to modify your classes in a reusable way.
>
> If your helpers are really global, which means that they are used by all, or 
> almost all your controllers, I would put them into your main application 
> class.
>
> If you have more than one application which make use of the same
> helpers: Put them into a role:
>
> YourHelperRole.pm:
>
>   package YourHelperRole;
>   use Moose::Role;
>
>   has "some_attribute" => ( ... ); # if you need attributes
>
>   sub helpermethod1{
> my ($self, $other, $args) = @_;
> do_something();
>   }
>
>   sub helpermethod2{
> my ($self, $other, $args) = @_;
> do_something_different();
>   }
>
>   no Moose::Role; # or use namespace::autoclean or MooseX::MarkAsMethod
>   1;
>
> App.pm:
>
>   use Catalyst qw( ... );
>   extends "Catalyst";
>   with qw/YourHelperRole/;
>
>   ...
>
> In my opinion, extending your main App.pm with roles is only useful if you 
> need the same helpers in different locations, too.
> If you only need them for that single application,  avoid the overhead 
> related to using roles.
>
> If you have helpers which are only needed by some controllers, create a role 
> for your controllers. You can not only implement helpers in you roles, you 
> can also create method-modifiers, which change the way your methods behave.
>
> Here is an example, which writes sth to the log, after the "delete"
> method was called:
>
> YourLogRole.pm:
>
>   package YourLogRole;
>
>   use Moose::Role;
>   requires qw/delete/; #die if the consuming class has no "delete"
>
>   after "delete" => sub{
> my ($self, $c) = @_;
> $c->log->debug("DELETE called");
>   };
>
>   no Moose::Role;
>   1;
>
> Controller1.pm: (has the helpers, but no logging)
>
>   package Controller1;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourHelperRole
>   /;
>
>   sub someaction :Local {
> my ($self, $c) =@_;
> $self->helpermethod1();
>   }
>
>   ...
>
> Controller2.pm: (has helpers AND logging)
>
>   package Controller2;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourLogRole
> YourHelperRole
>   /;
>
>   sub delete :Local :Args(1) { ... }
>
> Controller3.pm (has logging, but no helpers)
>
>   package Controller3;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourLogRole
>   /;
>
>   sub delete :Local :Args(1) { ... }
>
> Roles are very powerful tools. I use them a lot.
> Read the Moose docs for more information.
>
> If you don't want to learn Moose, roles and so on now, just remember:
>
> 1. write sth in a role
> 2. consume the role in a moose class, using "with"
> 3. your roles methods and attributes will be available in the
> consuming class
>
> Lukas
>
> O

Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Bill Moseley
On Tue, Oct 30, 2012 at 7:03 AM, Craig Chant
wrote:

>  So it seems it’s OK to whack them in the main MyApp.pm , here is an
> example of what is currently in a ‘MemberGlobs.pm’, which is ‘required’ in
> 90% of all the perl scripts.
>

Be careful with that approach.   I'd stick with method that need to get
inserted into the request cycle -- not just a catch-all for something you
don't know where it really belongs.


>
>
> ##
>
> # Yank Date #
>
> ##
>
> sub YankDate {
>
>
>
> #_[0] = UK Date
>
>
>
> # split to parts
>
> my @dte = split(/\//, $_[0]);
>

Where does $_ come from?   Now might be a good time to start using
PerlCritic because it's a pain later to try and clean up code.


>
>
> # rebuild to yank date
>
> my $yank = "$dte[2]-$dte[1]-$dte[0]";
>

Where's this date coming from?  The database?   Look at inflating all dates
and times to DateTime objects.

Then the rendering of that object becomes a View issue.

How do you see the timezone?   That's also a rendering/View issue.

It's not pretty, but what I tend to do in the View (say, in a Template) is:

Event Time: [% set_user_time_zone( event.start_time ).strftime( loc(
'_time_with_zone' ) ) %]

set_user_time_zone clones the DateTime object and sets the timezone and
locale on the DateTime objet.   The _time_with_zone is a string that gets
"translated" -- although mostly to %c, %x, and %X.  But, by using
localization it can be anything.



>
> # return result
>
> $yank;
>

Yes, check out PerlCritic.


> }
>
>
>
> I’m forever having to switch between UK dates and USA dates so have helper
> methods.
>

See above.



>
>
> Where do these go?
>
>
>
> Also where do you put application global constants?
>

Not a clear line, but you have an app config for app-specific config.  But,
I also have App::Constants that export constats which is useful for when
you need the constants outside of Catalyst.



-- 
Bill Moseley
mose...@hank.org
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Lukas Thiemeier
You can also define your constants in "YourApp/Constants.pl", and "use"
YourApp::Constants wherever you need them.

YourApp/Constants.pm:
  use constant { FOO => 1 };
  1;

Controller.pm:

  use YourApp::Constants;

  # and in some method
  ...
  my $global_foo = FOO;

There might be a better way, but this works...

For handling dates, I recommend "DateTime", available on cpan:

Another reason to use DBIC:
DBIx::Class::Inflatecolumn::DateTime automatically transforms dates
stored in a database into a DateTime object, which can be used like this:

my $uk_string = $datetime->dmy('/');
my $us_string = $datetime->ymd('-');

But DateTime is not related to DBIC, DBIC just makes using it easy.

Use it if you have to work with dates a lot. It has lots of methods for
outputting dates, times or both in different formats, and it allows
datetime-math...


On 10/30/2012 03:39 PM, Craig Chant wrote:
> Well I opted for putting my globals (methods and constants) in MyApp.pm
> 
> It's working grand with $c->myMethod or $c->MY_CONSTANT
> 
> I use to have them working as a bareword within my application , but 
> $c->MY_CONSTANT is just as easy!
> 
> Many thanks for all the input and help, it really is appreciated.
> 
> -Original Message-
> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 13:56
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Global 'helper' methods
> 
> Hi Craig,
> 
> Writing helpers in your main App.pm and using roles is not either-or.
> 
> Roles are one possibility to modify your classes in a reusable way.
> 
> If your helpers are really global, which means that they are used by all, or 
> almost all your controllers, I would put them into your main application 
> class.
> 
> If you have more than one application which make use of the same
> helpers: Put them into a role:
> 
> YourHelperRole.pm:
> 
>   package YourHelperRole;
>   use Moose::Role;
> 
>   has "some_attribute" => ( ... ); # if you need attributes
> 
>   sub helpermethod1{
> my ($self, $other, $args) = @_;
> do_something();
>   }
> 
>   sub helpermethod2{
> my ($self, $other, $args) = @_;
> do_something_different();
>   }
> 
>   no Moose::Role; # or use namespace::autoclean or MooseX::MarkAsMethod
>   1;
> 
> App.pm:
> 
>   use Catalyst qw( ... );
>   extends "Catalyst";
>   with qw/YourHelperRole/;
> 
>   ...
> 
> In my opinion, extending your main App.pm with roles is only useful if you 
> need the same helpers in different locations, too.
> If you only need them for that single application,  avoid the overhead 
> related to using roles.
> 
> If you have helpers which are only needed by some controllers, create a role 
> for your controllers. You can not only implement helpers in you roles, you 
> can also create method-modifiers, which change the way your methods behave.
> 
> Here is an example, which writes sth to the log, after the "delete"
> method was called:
> 
> YourLogRole.pm:
> 
>   package YourLogRole;
> 
>   use Moose::Role;
>   requires qw/delete/; #die if the consuming class has no "delete"
> 
>   after "delete" => sub{
> my ($self, $c) = @_;
> $c->log->debug("DELETE called");
>   };
> 
>   no Moose::Role;
>   1;
> 
> Controller1.pm: (has the helpers, but no logging)
> 
>   package Controller1;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourHelperRole
>   /;
> 
>   sub someaction :Local {
> my ($self, $c) =@_;
> $self->helpermethod1();
>   }
> 
>   ...
> 
> Controller2.pm: (has helpers AND logging)
> 
>   package Controller2;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourLogRole
> YourHelperRole
>   /;
> 
>   sub delete :Local :Args(1) { ... }
> 
> Controller3.pm (has logging, but no helpers)
> 
>   package Controller3;
>   use Moose;
>   extends "Catalyst::Controller";
>   with qw/
> YourLogRole
>   /;
> 
>   sub delete :Local :Args(1) { ... }
> 
> Roles are very powerful tools. I use them a lot.
> Read the Moose docs for more information.
> 
> If you don't want to learn Moose, roles and so on now, just remember:
> 
> 1. write sth in a role
> 2. consume the role in a moose class, using "with"
> 3. your roles methods and attributes will be available in the consuming class
> 
> Lukas
> 
> On 10/30/2012 02:03 PM, Craig Chant wrote:
>> Hi,
>>
>>
>>
>> Please could you advise the best way of having a global 'helper' class
>> that has all commonly used methods in it accessible for any part of
>> the catalyst app.
>>
>>
>>
>> I found this thread
>> http://stackoverflow.com/questions/11941836/catalyst-global-subroutine
>> s
>>
>>
>>
>> With one indicating it's ok to put them in the main MyApp.pm and
>> another saying to use Moose & Roles.
>>
>>
>>
>> What is considered the correct way and could you provide an example of
>> how I create this helper class and bolt it to the Catalyst application.
>>
>>
>>
>> Many thanks,
>>
>>
>>
>> */Craig Chant/*

RE: [Catalyst] Global 'helper' methods

2012-10-30 Thread Craig Chant
Well I opted for putting my globals (methods and constants) in MyApp.pm

It's working grand with $c->myMethod or $c->MY_CONSTANT

I use to have them working as a bareword within my application , but 
$c->MY_CONSTANT is just as easy!

Many thanks for all the input and help, it really is appreciated.

-Original Message-
From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
Sent: 30 October 2012 13:56
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Global 'helper' methods

Hi Craig,

Writing helpers in your main App.pm and using roles is not either-or.

Roles are one possibility to modify your classes in a reusable way.

If your helpers are really global, which means that they are used by all, or 
almost all your controllers, I would put them into your main application class.

If you have more than one application which make use of the same
helpers: Put them into a role:

YourHelperRole.pm:

  package YourHelperRole;
  use Moose::Role;

  has "some_attribute" => ( ... ); # if you need attributes

  sub helpermethod1{
my ($self, $other, $args) = @_;
do_something();
  }

  sub helpermethod2{
my ($self, $other, $args) = @_;
do_something_different();
  }

  no Moose::Role; # or use namespace::autoclean or MooseX::MarkAsMethod
  1;

App.pm:

  use Catalyst qw( ... );
  extends "Catalyst";
  with qw/YourHelperRole/;

  ...

In my opinion, extending your main App.pm with roles is only useful if you need 
the same helpers in different locations, too.
If you only need them for that single application,  avoid the overhead related 
to using roles.

If you have helpers which are only needed by some controllers, create a role 
for your controllers. You can not only implement helpers in you roles, you can 
also create method-modifiers, which change the way your methods behave.

Here is an example, which writes sth to the log, after the "delete"
method was called:

YourLogRole.pm:

  package YourLogRole;

  use Moose::Role;
  requires qw/delete/; #die if the consuming class has no "delete"

  after "delete" => sub{
my ($self, $c) = @_;
$c->log->debug("DELETE called");
  };

  no Moose::Role;
  1;

Controller1.pm: (has the helpers, but no logging)

  package Controller1;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourHelperRole
  /;

  sub someaction :Local {
my ($self, $c) =@_;
$self->helpermethod1();
  }

  ...

Controller2.pm: (has helpers AND logging)

  package Controller2;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourLogRole
YourHelperRole
  /;

  sub delete :Local :Args(1) { ... }

Controller3.pm (has logging, but no helpers)

  package Controller3;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourLogRole
  /;

  sub delete :Local :Args(1) { ... }

Roles are very powerful tools. I use them a lot.
Read the Moose docs for more information.

If you don't want to learn Moose, roles and so on now, just remember:

1. write sth in a role
2. consume the role in a moose class, using "with"
3. your roles methods and attributes will be available in the consuming class

Lukas

On 10/30/2012 02:03 PM, Craig Chant wrote:
> Hi,
>
>
>
> Please could you advise the best way of having a global 'helper' class
> that has all commonly used methods in it accessible for any part of
> the catalyst app.
>
>
>
> I found this thread
> http://stackoverflow.com/questions/11941836/catalyst-global-subroutine
> s
>
>
>
> With one indicating it's ok to put them in the main MyApp.pm and
> another saying to use Moose & Roles.
>
>
>
> What is considered the correct way and could you provide an example of
> how I create this helper class and bolt it to the Catalyst application.
>
>
>
> Many thanks,
>
>
>
> */Craig Chant/*
>
> I.T. Manager
>
> Description: cid:image001.png@01CD5F4A.17E848D0
>
> Main Line01903 602664
>
> Direct Line   01903 227753
>
> Visit our website http://www.homeloanpartnership.com
>
> *HomeLoan Partnership have been named the Best Mortgage Network, 2012,
> at the myintroducer.com Industry Awards*
>
>
>
> This Email and any attachments contain confidential information and is
> intended solely for the individual to whom it is addressed. If this
> Email has been misdirected, please notify the author as soon as
> possible. If you are not the intended recipient you must not disclose,
> distribute, copy, print or rely on any of the information contained,
> and all copies must be deleted immediately. Whilst we take reasonable
> steps to try to identify any software viruses, any attachments to this
> e-mail may nevertheless contain viruses, which our anti-virus software
> has failed to identify. You should therefore carry out your own
> anti-virus checks before opening any documents. HomeLoan Partnership
> will not accept any liability for damage caused by computer viruses
> emanating from any attachment or other document supplied with this e-mail.
> HomeLoan Partne

RE: [Catalyst] Global 'helper' methods

2012-10-30 Thread Craig Chant
So it seems it’s OK to whack them in the main MyApp.pm , here is an example of 
what is currently in a ‘MemberGlobs.pm’, which is ‘required’ in 90% of all the 
perl scripts.

##
# Yank Date #
##
sub YankDate {

#_[0] = UK Date

# split to parts
my @dte = split(/\//, $_[0]);

# rebuild to yank date
my $yank = "$dte[2]-$dte[1]-$dte[0]";

# return result
$yank;
}

I’m forever having to switch between UK dates and USA dates so have helper 
methods.

Where do these go?

Also where do you put application global constants?

Thanks,

Craig.

From: Dimitar Petrov [mailto:mita...@gmail.com]
Sent: 30 October 2012 13:52
To: The elegant MVC web framework
Subject: Re: [Catalyst] Global 'helper' methods

Hello Craig,

See the last answer. abraxxa describes it pretty well. Are those catalyst 
specific? Probably provide an example so someone could provide a better 
solution.

Cheers,
On Tue, Oct 30, 2012 at 2:03 PM, Craig Chant 
mailto:cr...@homeloanpartnership.com>> wrote:
Hi,

Please could you advise the best way of having a global ‘helper’ class that has 
all commonly used methods in it accessible for any part of the catalyst app.

I found this thread 
http://stackoverflow.com/questions/11941836/catalyst-global-subroutines

With one indicating it’s ok to put them in the main MyApp.pm and another saying 
to use Moose & Roles.

What is considered the correct way and could you provide an example of how I 
create this helper class and bolt it to the Catalyst application.

Many thanks,

Craig Chant
I.T. Manager
[Description: cid:image001.png@01CD5F4A.17E848D0]
Main Line01903 602664
Direct Line   01903 227753
Visit our website http://www.homeloanpartnership.com
HomeLoan Partnership have been named the Best Mortgage Network, 2012, at the 
myintroducer.com Industry Awards

This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.

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

This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.
<>___
List: Catalyst@lists.scsys.co.uk
Listinfo: http

Re: [Catalyst] Global 'helper' methods

2012-10-30 Thread Lukas Thiemeier
Hi Craig,

Writing helpers in your main App.pm and using roles is not either-or.

Roles are one possibility to modify your classes in a reusable way.

If your helpers are really global, which means that they are used by
all, or almost all your controllers, I would put them into your main
application class.

If you have more than one application which make use of the same
helpers: Put them into a role:

YourHelperRole.pm:

  package YourHelperRole;
  use Moose::Role;

  has "some_attribute" => ( ... ); # if you need attributes

  sub helpermethod1{
my ($self, $other, $args) = @_;
do_something();
  }

  sub helpermethod2{
my ($self, $other, $args) = @_;
do_something_different();
  }

  no Moose::Role; # or use namespace::autoclean or MooseX::MarkAsMethod
  1;

App.pm:

  use Catalyst qw( ... );
  extends "Catalyst";
  with qw/YourHelperRole/;

  ...

In my opinion, extending your main App.pm with roles is only useful if
you need the same helpers in different locations, too.
If you only need them for that single application,  avoid the overhead
related to using roles.

If you have helpers which are only needed by some controllers, create a
role for your controllers. You can not only implement helpers in you
roles, you can also create method-modifiers, which change the way your
methods behave.

Here is an example, which writes sth to the log, after the "delete"
method was called:

YourLogRole.pm:

  package YourLogRole;

  use Moose::Role;
  requires qw/delete/; #die if the consuming class has no "delete"

  after "delete" => sub{
my ($self, $c) = @_;
$c->log->debug("DELETE called");
  };

  no Moose::Role;
  1;

Controller1.pm: (has the helpers, but no logging)

  package Controller1;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourHelperRole
  /;

  sub someaction :Local {
my ($self, $c) =@_;
$self->helpermethod1();
  }

  ...

Controller2.pm: (has helpers AND logging)

  package Controller2;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourLogRole
YourHelperRole
  /;

  sub delete :Local :Args(1) { ... }

Controller3.pm (has logging, but no helpers)

  package Controller3;
  use Moose;
  extends "Catalyst::Controller";
  with qw/
YourLogRole
  /;

  sub delete :Local :Args(1) { ... }

Roles are very powerful tools. I use them a lot.
Read the Moose docs for more information.

If you don't want to learn Moose, roles and so on now, just remember:

1. write sth in a role
2. consume the role in a moose class, using "with"
3. your roles methods and attributes will be available in the consuming
class

Lukas

On 10/30/2012 02:03 PM, Craig Chant wrote:
> Hi,
> 
>  
> 
> Please could you advise the best way of having a global ‘helper’ class
> that has all commonly used methods in it accessible for any part of the
> catalyst app.
> 
>  
> 
> I found this thread
> http://stackoverflow.com/questions/11941836/catalyst-global-subroutines
> 
>  
> 
> With one indicating it’s ok to put them in the main MyApp.pm and another
> saying to use Moose & Roles.
> 
>  
> 
> What is considered the correct way and could you provide an example of
> how I create this helper class and bolt it to the Catalyst application.
> 
>  
> 
> Many thanks,
> 
>  
> 
> */Craig Chant/*
> 
> I.T. Manager
> 
> Description: cid:image001.png@01CD5F4A.17E848D0
> 
> Main Line01903 602664
> 
> Direct Line   01903 227753
> 
> Visit our website http://www.homeloanpartnership.com
> 
> *HomeLoan Partnership have been named the Best Mortgage Network, 2012,
> at the myintroducer.com Industry Awards*
> 
>  
> 
> This Email and any attachments contain confidential information and is
> intended solely for the individual to whom it is addressed. If this
> Email has been misdirected, please notify the author as soon as
> possible. If you are not the intended recipient you must not disclose,
> distribute, copy, print or rely on any of the information contained, and
> all copies must be deleted immediately. Whilst we take reasonable steps
> to try to identify any software viruses, any attachments to this e-mail
> may nevertheless contain viruses, which our anti-virus software has
> failed to identify. You should therefore carry out your own anti-virus
> checks before opening any documents. HomeLoan Partnership will not
> accept any liability for damage caused by computer viruses emanating
> from any attachment or other document supplied with this e-mail.
> HomeLoan Partnership reserves the right to monitor and archive all
> e-mail communications through its network. No representative or employee
> of HomeLoan Partnership has the authority to enter into any contract on
> behalf of HomeLoan Partnership by email. HomeLoan Partnership is a
> trading name of H L Partnership Limited, registered in England and Wales
> with Registration Number 5011722. Registered office: 26-34 Old Street,
> London, EC1V 9QQ. H L Partnership Limited is au

RE: [Catalyst] Why is $c undefined?

2012-10-30 Thread Craig Chant
Thanks Lukas,

I really appreciate your input and guidance, nice to know I'm thinking along 
the right lines, even if bending the rules and re-inventing the wheel in places.

Another thing I found with the built in ORM/DBIC (though correct me if I'm 
wrong), is it doesn't work with T-SQL Stored Procedures, which is where I am 
heading with a lot of my SQL functionality.

Let SQL do the work, and simply manipulate the returned recordset.

So I have in my underlying SQL helper class

# Stored Procedure SQL
sub spSQL {

#_0 = Self
#_1 = Stored Procedure with params!

# Declare Local Vars
my ($self,$sp) = @_;

# Connect
my $dbh = $self->dbh;

# Set Long Read (required for DBI & ODBC!)
$dbh->{LongReadLen} = 9;

# Run SQL Command
my $sth = $dbh->prepare("EXEC $sp") || die("Error in spSQL 
($self->{server}): $sp");
$sth->execute();

# Loop SQL Record Set
while (my $ref = $sth->fetchrow_hashref()) {
# Build Array of Hashes with SQL Data
$rs[@rs] = \%$ref;
}

# Return record set
return @rs;

}


Dunno, how do you execute SQL stored procedures using the inbuilt ORM/CRUD via 
DBIC ?

Craig.

-Original Message-
From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
Sent: 30 October 2012 12:52
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Why is $c undefined?

Hi Craig,

You don't understand why "$c->model('Model1')" retrieves and data, because it 
doesn't retrieve any data.

Database-code in the controller should be avoided, and instead be implemented 
in the model.

My code just passes a reference to "Model2" to "Model1", so "Model1" can access 
data from "Model2".

Within "Model1", you can use prepare, execute, fetch et cetera on "Model1" and 
"Model2", to fetch the data for your calculations.

Nevertheless, i think that your idea to create a extra model, which has access 
to both underlying databases, is a better choice.

Lukas

On 10/30/2012 01:16 PM, Craig Chant wrote:
> Thanks Lukas,
>
> Chained method calls is not my strong point in Perl, they seem easier to read 
> in other languages with bracketed encapsulation and the dot notation.
>
> Your helper method is interesting, though I don't understand how 
> $c->model("Model1"); retrieves any SQL data, like I said wrapping my head 
> around this is a bit of an uphill struggle currently.
>
> Regards,
>
> Craig.
>
>
> -Original Message-
> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 11:28
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Why is $c undefined?
>
> Hi Craig,
>
> On 10/30/2012 12:09 PM, Craig Chant wrote:
>> Thanks Ian,
>>
>> The hierarchy is something that I am finding mind-blowing at the moment,
>> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
>> $self, passing in $self, I'm sure it makes sense to you :-)
>>
>
> No, he is calling "render" on whatever is returned by $self->jqgrid.
> Thats why $self has to be passed to "render". The code above is equivalent to:
>
>   my $jqgrid = $self->jqgrid;
>   $jqgrid->render($self, ...);
>
>
>> One thing I would like clarification with if possible.
>>
>> Where do I put code that requires the use of more than one model?
>>
>> Do I create a separate model that acts as an interface between the other 
>> models?
>
> Thats one possibility. Another possibility would be to create a helper method 
> in Model1, which expects Model2 as a parameter.
>
> Model1.pm:
>
>   sub calculate_sth_with_model2{
> my ($self, $model2) = @_;
> do_crazy_calculations();
>   }
>
> And in your Controller:
>
>   sub calculate :Local :Args(0) {
> my ($self, $c) = @_;
>
> my $m1 = $c->model("Model1");
> my $m2 = $c->model("Model2");
>
> $m1->calculate_sth_with_model2($m2);
>
>   }
>
>>
>> You see I have two SQL servers in opposite ends of the country and so I have 
>> a model built on Model::DBI that can access one server and another Model 
>> that can access the other, but I have functionality that needs data from 
>> both , do some calculations and output accordingly.
>>
>> I assume this does not go in the controller, but I create an interface model 
>> with the required methods and functionality that the controller uses?
>>
>> Regards,
>>
>> Craig.
>>
>> -Original Message-
>> From: Ian Docherty [mailto:catal...@iandocherty.com]
>> Sent: 30 October 2012 07:22
>> To: The elegant MVC web framework
>> Subject: Re: [Catalyst] Why is $c undefined?
>>
>> On 29 October 2012 21:01, Craig Chant  wrote:
>> ...
>>>
>>> I have read and seen frameworks such as Mojolicious encourage a shrinkage 
>>> of the Model and move alot of functionality to the Controller, so there is 
>>> a paradigm which seems to imply it is ok to do more stuff in the 
>>> Controller, but I am leaning towards having the main code in the Model and 
>>> then bolting it together via the Controller.
>>>
>> I can understand why you get this

[Catalyst] Global 'helper' methods

2012-10-30 Thread Craig Chant
Hi,

Please could you advise the best way of having a global 'helper' class that has 
all commonly used methods in it accessible for any part of the catalyst app.

I found this thread 
http://stackoverflow.com/questions/11941836/catalyst-global-subroutines

With one indicating it's ok to put them in the main MyApp.pm and another saying 
to use Moose & Roles.

What is considered the correct way and could you provide an example of how I 
create this helper class and bolt it to the Catalyst application.

Many thanks,

Craig Chant
I.T. Manager
[Description: cid:image001.png@01CD5F4A.17E848D0]
Main Line01903 602664
Direct Line   01903 227753
Visit our website http://www.homeloanpartnership.com
HomeLoan Partnership have been named the Best Mortgage Network, 2012, at the 
myintroducer.com Industry Awards

This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.
<>___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Lukas Thiemeier
Hi Craig,

You don't understand why "$c->model('Model1')" retrieves and data,
because it doesn't retrieve any data.

Database-code in the controller should be avoided, and instead be
implemented in the model.

My code just passes a reference to "Model2" to "Model1", so "Model1" can
access data from "Model2".

Within "Model1", you can use prepare, execute, fetch et cetera on
"Model1" and "Model2", to fetch the data for your calculations.

Nevertheless, i think that your idea to create a extra model, which has
access to both underlying databases, is a better choice.

Lukas

On 10/30/2012 01:16 PM, Craig Chant wrote:
> Thanks Lukas,
> 
> Chained method calls is not my strong point in Perl, they seem easier to read 
> in other languages with bracketed encapsulation and the dot notation.
> 
> Your helper method is interesting, though I don't understand how 
> $c->model("Model1"); retrieves any SQL data, like I said wrapping my head 
> around this is a bit of an uphill struggle currently.
> 
> Regards,
> 
> Craig.
> 
> 
> -Original Message-
> From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
> Sent: 30 October 2012 11:28
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Why is $c undefined?
> 
> Hi Craig,
> 
> On 10/30/2012 12:09 PM, Craig Chant wrote:
>> Thanks Ian,
>>
>> The hierarchy is something that I am finding mind-blowing at the moment,
>> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
>> $self, passing in $self, I'm sure it makes sense to you :-)
>>
> 
> No, he is calling "render" on whatever is returned by $self->jqgrid.
> Thats why $self has to be passed to "render". The code above is equivalent to:
> 
>   my $jqgrid = $self->jqgrid;
>   $jqgrid->render($self, ...);
> 
> 
>> One thing I would like clarification with if possible.
>>
>> Where do I put code that requires the use of more than one model?
>>
>> Do I create a separate model that acts as an interface between the other 
>> models?
> 
> Thats one possibility. Another possibility would be to create a helper method 
> in Model1, which expects Model2 as a parameter.
> 
> Model1.pm:
> 
>   sub calculate_sth_with_model2{
> my ($self, $model2) = @_;
> do_crazy_calculations();
>   }
> 
> And in your Controller:
> 
>   sub calculate :Local :Args(0) {
> my ($self, $c) = @_;
> 
> my $m1 = $c->model("Model1");
> my $m2 = $c->model("Model2");
> 
> $m1->calculate_sth_with_model2($m2);
> 
>   }
> 
>>
>> You see I have two SQL servers in opposite ends of the country and so I have 
>> a model built on Model::DBI that can access one server and another Model 
>> that can access the other, but I have functionality that needs data from 
>> both , do some calculations and output accordingly.
>>
>> I assume this does not go in the controller, but I create an interface model 
>> with the required methods and functionality that the controller uses?
>>
>> Regards,
>>
>> Craig.
>>
>> -Original Message-
>> From: Ian Docherty [mailto:catal...@iandocherty.com]
>> Sent: 30 October 2012 07:22
>> To: The elegant MVC web framework
>> Subject: Re: [Catalyst] Why is $c undefined?
>>
>> On 29 October 2012 21:01, Craig Chant  wrote:
>> ...
>>>
>>> I have read and seen frameworks such as Mojolicious encourage a shrinkage 
>>> of the Model and move alot of functionality to the Controller, so there is 
>>> a paradigm which seems to imply it is ok to do more stuff in the 
>>> Controller, but I am leaning towards having the main code in the Model and 
>>> then bolting it together via the Controller.
>>>
>> I can understand why you get this impression, I think a lot of people end up 
>> putting code in the Controller when they first start using MVC (I did so 
>> myself in the past).
>>
>> The Model should be external to your Catalyst app (or whatever framework you 
>> use) so that you can use it in things like cron jobs. It also makes testing 
>> easier if your Model is separate from your Catalyst app. Look at using 
>> something like Catalyst::Model::Adaptor as a thin shell to add your external 
>> Model into Catalyst.
>>
>> I am moving more and more into making my Controllers as thin as
>> possible. Logic that I might have previously put into the Controller,
>> I either put into the Model or I create helper functions. Here is an
>> example of a Controller (from Mojolicious as it happens but that is
>> not important)
>>
>> sub user_list {
>> my ($self) = @_;
>>
>> $self->jqgrid->render($self, {
>> rs  => $self->schema->resultset('User')->search_rs,
>> filters => {},
>> rows=> [qw(id name)],
>> });
>> }
>>
>> It's not important to know what is going on here, but this Controller gets a 
>> list of all users, formats the data for use in the jQuery jqGrid allows for 
>> sorting and filtering and outputs the data in JSON format. The point being, 
>> the controller code is kept simple and 'thin'
>> and yet it does a lot of work behind

RE: [Catalyst] Why is $c undefined?

2012-10-30 Thread Craig Chant
Cool, thanks Ian.

I am trying to build my models based on functionality around the DBIC ethos, 
not quite as a direct model->table mapping as DBIC creates, but for example all 
functions that require access to the 'Users' table, will have a 'Users' model 
and all functionality regarding logins, logouts, user name and other stuff kept 
in that model.

Separating it all into the correct models with all the desired methods isn't 
easy and will take time to formulate, but even though I'm not using Catalysts 
ORM/CRUD, I am still trying to stick to an MVC paradigm!

I have a long way to go for sure!

Craig.

-Original Message-
From: Ian Docherty [mailto:catal...@iandocherty.com]
Sent: 30 October 2012 11:25
To: The elegant MVC web framework
Subject: Re: [Catalyst] Why is $c undefined?

On 30 October 2012 11:09, Craig Chant  wrote:
> Thanks Ian,
>
> The hierarchy is something that I am finding mind-blowing at the moment,
> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
> $self, passing in $self, I'm sure it makes sense to you :-)
>
> One thing I would like clarification with if possible.
>
> Where do I put code that requires the use of more than one model?
>
> Do I create a separate model that acts as an interface between the other 
> models?
>
> You see I have two SQL servers in opposite ends of the country and so I have 
> a model built on Model::DBI that can access one server and another Model that 
> can access the other, but I have functionality that needs data from both , do 
> some calculations and output accordingly.
>
> I assume this does not go in the controller, but I create an interface model 
> with the required methods and functionality that the controller uses?
>
Craig. Yes, try to keep it out of the Controller.

My opinion is, that if you have business logic that uses data from two SQL 
servers (each of which has it's own model) then this would be a model in it's 
own right. First think of this business logic outside of Catalyst, it might 
have accessors for each of the SQL instance objects. Create a BusinessModel for 
this logic. You might find that this then becomes the only Model that you need 
to access from Catalyst, and the SQL server objects are not directly called 
from Catalyst, but are subsumed by BusinessModel.

Then use Catalyst::Model::Adaptor with your BusinessModel giving Catalyst 
access to all of it's methods.

Kind Regards
Ian

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.

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


RE: [Catalyst] Why is $c undefined?

2012-10-30 Thread Craig Chant
Thanks Lukas,

Chained method calls is not my strong point in Perl, they seem easier to read 
in other languages with bracketed encapsulation and the dot notation.

Your helper method is interesting, though I don't understand how 
$c->model("Model1"); retrieves any SQL data, like I said wrapping my head 
around this is a bit of an uphill struggle currently.

Regards,

Craig.


-Original Message-
From: Lukas Thiemeier [mailto:spamcatc...@thiemeier.net]
Sent: 30 October 2012 11:28
To: The elegant MVC web framework
Subject: Re: [Catalyst] Why is $c undefined?

Hi Craig,

On 10/30/2012 12:09 PM, Craig Chant wrote:
> Thanks Ian,
>
> The hierarchy is something that I am finding mind-blowing at the moment,
> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
> $self, passing in $self, I'm sure it makes sense to you :-)
>

No, he is calling "render" on whatever is returned by $self->jqgrid.
Thats why $self has to be passed to "render". The code above is equivalent to:

  my $jqgrid = $self->jqgrid;
  $jqgrid->render($self, ...);


> One thing I would like clarification with if possible.
>
> Where do I put code that requires the use of more than one model?
>
> Do I create a separate model that acts as an interface between the other 
> models?

Thats one possibility. Another possibility would be to create a helper method 
in Model1, which expects Model2 as a parameter.

Model1.pm:

  sub calculate_sth_with_model2{
my ($self, $model2) = @_;
do_crazy_calculations();
  }

And in your Controller:

  sub calculate :Local :Args(0) {
my ($self, $c) = @_;

my $m1 = $c->model("Model1");
my $m2 = $c->model("Model2");

$m1->calculate_sth_with_model2($m2);

  }

>
> You see I have two SQL servers in opposite ends of the country and so I have 
> a model built on Model::DBI that can access one server and another Model that 
> can access the other, but I have functionality that needs data from both , do 
> some calculations and output accordingly.
>
> I assume this does not go in the controller, but I create an interface model 
> with the required methods and functionality that the controller uses?
>
> Regards,
>
> Craig.
>
> -Original Message-
> From: Ian Docherty [mailto:catal...@iandocherty.com]
> Sent: 30 October 2012 07:22
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Why is $c undefined?
>
> On 29 October 2012 21:01, Craig Chant  wrote:
> ...
>>
>> I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
>> the Model and move alot of functionality to the Controller, so there is a 
>> paradigm which seems to imply it is ok to do more stuff in the Controller, 
>> but I am leaning towards having the main code in the Model and then bolting 
>> it together via the Controller.
>>
> I can understand why you get this impression, I think a lot of people end up 
> putting code in the Controller when they first start using MVC (I did so 
> myself in the past).
>
> The Model should be external to your Catalyst app (or whatever framework you 
> use) so that you can use it in things like cron jobs. It also makes testing 
> easier if your Model is separate from your Catalyst app. Look at using 
> something like Catalyst::Model::Adaptor as a thin shell to add your external 
> Model into Catalyst.
>
> I am moving more and more into making my Controllers as thin as
> possible. Logic that I might have previously put into the Controller,
> I either put into the Model or I create helper functions. Here is an
> example of a Controller (from Mojolicious as it happens but that is
> not important)
>
> sub user_list {
> my ($self) = @_;
>
> $self->jqgrid->render($self, {
> rs  => $self->schema->resultset('User')->search_rs,
> filters => {},
> rows=> [qw(id name)],
> });
> }
>
> It's not important to know what is going on here, but this Controller gets a 
> list of all users, formats the data for use in the jQuery jqGrid allows for 
> sorting and filtering and outputs the data in JSON format. The point being, 
> the controller code is kept simple and 'thin'
> and yet it does a lot of work behind the scenes.
>
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/ This Email and any attachments
> contain confidential information and is intended solely for the
> individual to whom it is addressed. If this Email has been
> misdirected, please notify the author as soon as possible. If you are
> not the intended recipient you must not disclose, distribute, copy,
> print or rely on any of the information contained, and all copies must
> be deleted immediately. Whilst we take reasonable steps to try to
> identify any software viruses, any attachments to this e-mail may

RE: [Catalyst] Unable to output anything in Root.pm -> 'auto'

2012-10-30 Thread Craig Chant
"What was the reason for not using DBIC again?"

The non-normalised DB with a  missing schema and the fact the data is spread 
across two SQL servers on separate DSN's.

I also want my data in a way I can manipulate it, maybe you are all going to 
fall down in shock and horror, but I get my records and pass them back as an 
array of hashes (recordset), I then play with them , manipulate them, and do 
all sorts of stuff with them.

ORM / DBIC doesn't seem to give you this type of access, it wants a DB schema 
with relationship mapping to dynamically create all the 1-many / many - many 
etc Models and relationships, which won't work with our system, from what I can 
tell.

This is my SQL helper class (well two methods as an example)

# Get SQL Routine
sub getSQL {

#_0 = Self
#_1 = Table
#_2 = Columns
#_3 = Where
#_4 = Order By

my ($self,$table,$columns,$where,$order) = @_;

# Build SQL Statement
my $sel = "SELECT $columns FROM $table WHERE $where";

# Check for ORDER BY
if(defined $order){$sel .= " ORDER BY $order";}

# Connect
my $dbh = $self->dbh;

# set long read because SQL requires it for ODBC
$dbh->{LongReadLen} = 9;

# Run SQL Command
my $sth = $db->prepare("$sel") || $self->sql_error("Error in getSQL (Web 
Server): $sel");
$sth->execute();

# Declare recordset array
my @rs;

# Loop SQL & build recordset
while (my $ref = $sth->fetchrow_hashref()) {
# Build Array of Hashes with SQL Data
$rs[@rs] = \%$ref;
}

# Return record set
@rs;

}

# Count SQL Routine
sub cntSQL {

#_0 = Self
#_1 = Table
#_2 = Where

my ($self,$table,$where) = @_;

#Build SQL Statement
my $sel = "SELECT COUNT(1) as COUNT FROM $table WHERE $where";

# Connect
my $dbh = $self->dbh;

# Run SQL Command
my $sth = $dbh->prepare("$sel") || $self->sql_error("Error in getSQL (Web 
Server): $sel");
$sth->execute();

# Loop SQL Record Set
while (my $ref = $sth->fetchrow_hashref()) {
# Build Array of Hashes with SQL Data
$rs[@rs] = \%$ref;
}

# Return Count
   $rs[0]->{'COUNT'};

}

It's just before the return of the record set or count I was wondering if I 
need to add '$sth->finish();' or '$dbh->disconnect();' - which I have in my 
current (non-catalyst) app version of the class (module).

I also believe that DBIC gets all columns from all tables, which I don't want, 
dunno, perhaps I'm missing something with DBIC, but I understand my data the 
way I retrieve it and didn't think there was anything wrong with using my SQL 
class, it has served me well for 10 years, and powers all my current apps.

How would I use DBIC to get records from two separate DSN's and merge 
recordsets?

In my concrete Catalyst::Model I have...

# Check if system locked
if($self->cntSQL('IsLock',"Locked='yes'")){
$c->response->body('Sorry, system is currently undergoing 
maintenance.Please try again later.' );
return 1;
}

One thing I have found already is the app doesn't seem to see real time SQL 
updates even if I issue$sth->finish(); &   $dbh->disconnect(); at the end 
of my method.

I make a manual change to SQL (switch the 'Locked' flag between 'yes' & 'no') , 
refresh the app and it isn't registering the SQL change, so already it seems 
something is being cached somewhere and I need to stop this, my apps need to 
see DB changes instantly.

Your advice is appreciated.

Craig.

-Original Message-
From: Rob Brown [mailto:r...@intelcompute.com]
Sent: 29 October 2012 22:30
To: catalyst@lists.scsys.co.uk
Subject: Re: [Catalyst] Unable to output anything in Root.pm -> 'auto'

basically...

$sth->finish if you've finished with the results of that statement, ie, you've 
looped through the rows and are now done.

$dbh->disconnect if you've finished with the database connection, tho now you 
start to think about working in a persistent environment, where you may never 
disconnect from the database, and/or have some connection caching setup.

This is where DBIx::Class just takes of all this for you - it does sound like 
you're re-inventing a lot here.

What was the reason for not using DBIC again?




On 10/29/2012 10:10 PM, Craig Chant wrote:
> I finally got to grips with extending my own class with the inbuilt $c->dbh.
>
> But am unsure whether I am mean to issue either...
>
>  $sth->finish();
>
>  or
>
> $dbh->disconnect();
>
> Once I have prepared / executed the SQL and fetched the records I want.
>
> so a little further guidance is appreciated.
>
> Craig
>
> 
> From: Lukas Thiemeier [spamcatc...@thiemeier.net]
> Sent: 29 October 2012 20:16
> To: catalyst@lists.scsys.co.uk
> Subject: Re: [Catalyst] Unable to output anything in Root.pm ->  'auto'
>
> Hi Craig,
>
> Using C::M::DBI is straight forward. Install it from cpan, and run
>
>script/yourapp.pl create model DBI DBI d

Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Lukas Thiemeier
Hi Craig,

On 10/30/2012 12:09 PM, Craig Chant wrote:
> Thanks Ian,
> 
> The hierarchy is something that I am finding mind-blowing at the moment,
> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
> $self, passing in $self, I'm sure it makes sense to you :-)
> 

No, he is calling "render" on whatever is returned by $self->jqgrid.
Thats why $self has to be passed to "render". The code above is
equivalent to:

  my $jqgrid = $self->jqgrid;
  $jqgrid->render($self, ...);


> One thing I would like clarification with if possible.
> 
> Where do I put code that requires the use of more than one model?
> 
> Do I create a separate model that acts as an interface between the other 
> models?

Thats one possibility. Another possibility would be to create a helper
method in Model1, which expects Model2 as a parameter.

Model1.pm:

  sub calculate_sth_with_model2{
my ($self, $model2) = @_;
do_crazy_calculations();
  }

And in your Controller:

  sub calculate :Local :Args(0) {
my ($self, $c) = @_;

my $m1 = $c->model("Model1");
my $m2 = $c->model("Model2");

$m1->calculate_sth_with_model2($m2);

  }

> 
> You see I have two SQL servers in opposite ends of the country and so I have 
> a model built on Model::DBI that can access one server and another Model that 
> can access the other, but I have functionality that needs data from both , do 
> some calculations and output accordingly.
> 
> I assume this does not go in the controller, but I create an interface model 
> with the required methods and functionality that the controller uses?
> 
> Regards,
> 
> Craig.
> 
> -Original Message-
> From: Ian Docherty [mailto:catal...@iandocherty.com]
> Sent: 30 October 2012 07:22
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Why is $c undefined?
> 
> On 29 October 2012 21:01, Craig Chant  wrote:
> ...
>>
>> I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
>> the Model and move alot of functionality to the Controller, so there is a 
>> paradigm which seems to imply it is ok to do more stuff in the Controller, 
>> but I am leaning towards having the main code in the Model and then bolting 
>> it together via the Controller.
>>
> I can understand why you get this impression, I think a lot of people end up 
> putting code in the Controller when they first start using MVC (I did so 
> myself in the past).
> 
> The Model should be external to your Catalyst app (or whatever framework you 
> use) so that you can use it in things like cron jobs. It also makes testing 
> easier if your Model is separate from your Catalyst app. Look at using 
> something like Catalyst::Model::Adaptor as a thin shell to add your external 
> Model into Catalyst.
> 
> I am moving more and more into making my Controllers as thin as possible. 
> Logic that I might have previously put into the Controller, I either put into 
> the Model or I create helper functions. Here is an example of a Controller 
> (from Mojolicious as it happens but that is not important)
> 
> sub user_list {
> my ($self) = @_;
> 
> $self->jqgrid->render($self, {
> rs  => $self->schema->resultset('User')->search_rs,
> filters => {},
> rows=> [qw(id name)],
> });
> }
> 
> It's not important to know what is going on here, but this Controller gets a 
> list of all users, formats the data for use in the jQuery jqGrid allows for 
> sorting and filtering and outputs the data in JSON format. The point being, 
> the controller code is kept simple and 'thin'
> and yet it does a lot of work behind the scenes.
> 
> ___
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
> This Email and any attachments contain confidential information and is 
> intended solely for the individual to whom it is addressed. If this Email has 
> been misdirected, please notify the author as soon as possible. If you are 
> not the intended recipient you must not disclose, distribute, copy, print or 
> rely on any of the information contained, and all copies must be deleted 
> immediately. Whilst we take reasonable steps to try to identify any software 
> viruses, any attachments to this e-mail may nevertheless contain viruses, 
> which our anti-virus software has failed to identify. You should therefore 
> carry out your own anti-virus checks before opening any documents. HomeLoan 
> Partnership will not accept any liability for damage caused by computer 
> viruses emanating from any attachment or other document supplied with this 
> e-mail. HomeLoan Partnership reserves the right to monitor and archive all 
> e-mail communications through its network. No representative or employee of 
> HomeLoan Partn
 ership ha
s the authority to enter 

Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Ian Docherty
On 30 October 2012 11:09, Craig Chant  wrote:
> Thanks Ian,
>
> The hierarchy is something that I am finding mind-blowing at the moment,
> "$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
> $self, passing in $self, I'm sure it makes sense to you :-)
>
> One thing I would like clarification with if possible.
>
> Where do I put code that requires the use of more than one model?
>
> Do I create a separate model that acts as an interface between the other 
> models?
>
> You see I have two SQL servers in opposite ends of the country and so I have 
> a model built on Model::DBI that can access one server and another Model that 
> can access the other, but I have functionality that needs data from both , do 
> some calculations and output accordingly.
>
> I assume this does not go in the controller, but I create an interface model 
> with the required methods and functionality that the controller uses?
>
Craig. Yes, try to keep it out of the Controller.

My opinion is, that if you have business logic that uses data from two
SQL servers (each of which has it's own model) then this would be a
model in it's own right. First think of this business logic outside of
Catalyst, it might have accessors for each of the SQL instance
objects. Create a BusinessModel for this logic. You might find that
this then becomes the only Model that you need to access from
Catalyst, and the SQL server objects are not directly called from
Catalyst, but are subsumed by BusinessModel.

Then use Catalyst::Model::Adaptor with your BusinessModel giving
Catalyst access to all of it's methods.

Kind Regards
Ian

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


RE: [Catalyst] Why is $c undefined?

2012-10-30 Thread Craig Chant
Thanks Ian,

The hierarchy is something that I am finding mind-blowing at the moment,
"$self->jqgrid->render($self," , you are calling methods jqgrid->render on 
$self, passing in $self, I'm sure it makes sense to you :-)

One thing I would like clarification with if possible.

Where do I put code that requires the use of more than one model?

Do I create a separate model that acts as an interface between the other models?

You see I have two SQL servers in opposite ends of the country and so I have a 
model built on Model::DBI that can access one server and another Model that can 
access the other, but I have functionality that needs data from both , do some 
calculations and output accordingly.

I assume this does not go in the controller, but I create an interface model 
with the required methods and functionality that the controller uses?

Regards,

Craig.

-Original Message-
From: Ian Docherty [mailto:catal...@iandocherty.com]
Sent: 30 October 2012 07:22
To: The elegant MVC web framework
Subject: Re: [Catalyst] Why is $c undefined?

On 29 October 2012 21:01, Craig Chant  wrote:
...
>
> I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
> the Model and move alot of functionality to the Controller, so there is a 
> paradigm which seems to imply it is ok to do more stuff in the Controller, 
> but I am leaning towards having the main code in the Model and then bolting 
> it together via the Controller.
>
I can understand why you get this impression, I think a lot of people end up 
putting code in the Controller when they first start using MVC (I did so myself 
in the past).

The Model should be external to your Catalyst app (or whatever framework you 
use) so that you can use it in things like cron jobs. It also makes testing 
easier if your Model is separate from your Catalyst app. Look at using 
something like Catalyst::Model::Adaptor as a thin shell to add your external 
Model into Catalyst.

I am moving more and more into making my Controllers as thin as possible. Logic 
that I might have previously put into the Controller, I either put into the 
Model or I create helper functions. Here is an example of a Controller (from 
Mojolicious as it happens but that is not important)

sub user_list {
my ($self) = @_;

$self->jqgrid->render($self, {
rs  => $self->schema->resultset('User')->search_rs,
filters => {},
rows=> [qw(id name)],
});
}

It's not important to know what is going on here, but this Controller gets a 
list of all users, formats the data for use in the jQuery jqGrid allows for 
sorting and filtering and outputs the data in JSON format. The point being, the 
controller code is kept simple and 'thin'
and yet it does a lot of work behind the scenes.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended 
solely for the individual to whom it is addressed. If this Email has been 
misdirected, please notify the author as soon as possible. If you are not the 
intended recipient you must not disclose, distribute, copy, print or rely on 
any of the information contained, and all copies must be deleted immediately. 
Whilst we take reasonable steps to try to identify any software viruses, any 
attachments to this e-mail may nevertheless contain viruses, which our 
anti-virus software has failed to identify. You should therefore carry out your 
own anti-virus checks before opening any documents. HomeLoan Partnership will 
not accept any liability for damage caused by computer viruses emanating from 
any attachment or other document supplied with this e-mail. HomeLoan 
Partnership reserves the right to monitor and archive all e-mail communications 
through its network. No representative or employee of HomeLoan Partnership has 
the authority to enter into any contract on behalf of HomeLoan Partnership by 
email. HomeLoan Partnership is a trading name of H L Partnership Limited, 
registered in England and Wales with Registration Number 5011722. Registered 
office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is 
authorised and regulated by the Financial Services Authority.

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


Re: [Catalyst] Why is $c undefined?

2012-10-30 Thread Ian Docherty
On 29 October 2012 21:01, Craig Chant  wrote:
...
>
> I have read and seen frameworks such as Mojolicious encourage a shrinkage of 
> the Model and move alot of functionality to the Controller, so there is a 
> paradigm which seems to imply it is ok to do more stuff in the Controller, 
> but I am leaning towards having the main code in the Model and then bolting 
> it together via the Controller.
>
I can understand why you get this impression, I think a lot of people
end up putting code in the Controller when they first start using MVC
(I did so myself in the past).

The Model should be external to your Catalyst app (or whatever
framework you use) so that you can use it in things like cron jobs. It
also makes testing easier if your Model is separate from your Catalyst
app. Look at using something like Catalyst::Model::Adaptor as a thin
shell to add your external Model into Catalyst.

I am moving more and more into making my Controllers as thin as
possible. Logic that I might have previously put into the Controller,
I either put into the Model or I create helper functions. Here is an
example of a Controller (from Mojolicious as it happens but that is
not important)

sub user_list {
my ($self) = @_;

$self->jqgrid->render($self, {
rs  => $self->schema->resultset('User')->search_rs,
filters => {},
rows=> [qw(id name)],
});
}

It's not important to know what is going on here, but this Controller
gets a list of all users, formats the data for use in the jQuery
jqGrid allows for sorting and filtering and outputs the data in JSON
format. The point being, the controller code is kept simple and 'thin'
and yet it does a lot of work behind the scenes.

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