Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

It's difficult for me to title this question, because I'm not sure which Catalyst magic I'm breaking. I'm new to Catalyst and Moose and lost in all the pod.

I'm trying to add generic JSON support to a Catalyst model. To do so, I add a TO_JSON object to my result class(es):

package MyApp::Schema::DB::Result::Table; ... extends 'DBIx::Class::Core'; ... sub TO_JSON { return { $_[0]->get_inflated_columns }; }

and extend Catalyst::View::JSON with some code I found. (I've stumbled on different approaches since--opinions on best approach for this also welcomed):

package MyApp::View::JSON; use Moose; use JSON::XS (); extends 'Catalyst::View::JSON'; my $encoder = JSON::XS->new->utf8->pretty(0)->indent(0) ->allow_blessed(1)->convert_blessed(1); sub encode_json { my( $self, $c, $data ) = @_; $encoder->encode( $data ); }

This works for each result class individually, but I'd like it to be DRYer. So, I think to create a result base class and extend that for my result classes...

package MyApp::Schema::DB::Result::Base; use Moose; use namespace::autoclean; extends 'DBIx::Class::Core'; sub TO_JSON {...} package MyApp::Schema::DB::Result::Table; ... extends 'MyApp::Schema::DB::Result::Base'; ...

Catalyst doesn't like this approach, yet, and I'm having a hard time figuring out which doc to read.

Do I just need to tell Catalyst to ignore the '...::Base' class when loading namespaces (or whatever)?

Or should I be doing this some other way entirely?

--Solo

--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

In reply to How to add TO_JSON base method for DBIC Result in Catalyst by Solo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2021-09-21 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?